ios
-
SPM을 사용하는 프로젝트에서 SPM의 번들에 접근하고 싶은 경우Swift 2022. 10. 28. 01:31
제목이 좀 길긴하지만, 최대한 쉽게 간단하게 적어보았다. 내가 만든 spm에서 사용하는 번들 내부에 있는 리소스들을 (asset파일, json 파일 등)을 spm을 적용시킨 프로젝트에서 사용하고 싶은 경우가 있을 수 있다. 그럴 경우 spm 내부에서 정말 간단하게 extension을 하나 걸어주면 된다. 위 처럼 Bundle의 extension으로 타입 프로퍼티 변수로 하나 만들어주면, 프로젝트에서 해당 spm Bundle에 마음껏 접근이 가능하다. 다음은 사용 예시다. 매우 간단하다. 이건 조금 case가 드물 수도 있어서 적어본다. 위와 같은 형식으로 SwiftUI modifier를 View에 extension 시키는 함수가 있었다. 너무도 당연하게 Color의 "BackgroundColor"가 as..
-
SPM에서 asset 파일 사용 방법Swift 2022. 10. 28. 01:11
SPM에서 asset 파일을 사용하고 싶은 경우 아래처럼 MyLibrary(최상위 spm 이름) -> Sources -> MyLibrary 내부에 asset 파일을 새롭게 추가하면 된다. asset 파일을 추가하게 되면 기존과는 다르게 Media라는 이름으로 파일이 생성되게 된다. asset 파일은 따로 Package.swift 파일에서 각 타겟들에 resources에 추가해주지 않아도 알아서 번들화를 시켜준다. 이렇게 세팅을 해준 후에 이미지나 컬러 등을 추가해주고 사용하면 된다. 찾다보면 여러가지 방법들이 다양하게 나오지만, Bundle.module 이런식으로 사용해주면 정상적으로 뜨는 것을 확인할 수 있다. 예시) SPM에서 asset 파일 외의 resource 들을 사용하고 싶다면? 예시로 jso..
-
MVC 패턴이란?Swift 2020. 12. 22. 10:00
MVC 패턴은 Model - View - ViewController로 이루어진 형태의 desgin pattern이다. 현재 iOS에서 굉장히 많이 사용되고 있는 디자인 패턴이며, 애플에서 권장하는 디자인 패턴이기도 하다. 하지만 최근 MVVM 패턴의 선언형 프레임워크인 SwiftUI가 나오면서 필자는 사용해 본적 없는 MVVM 패턴과 MVC 패턴의 차이점을 명확히 알고자 정리하게 되었다. 들어가기 전 간단정리! Model은 앱에서 사용되는 데이터들을 관리 및 구성(?)하는 역할 View는 데이터를 보여주는 역할이다. ViewController는 View와 Model의 사이에서 유저의 인터렉션을 처리해주어 액션에 따라 View와 Model간의 중재를 한다. Model을 업데이트 해주고 Model과 View..
-
Handling User Input 예제 정리SwiftUI/Document 예제 2020. 12. 19. 10:00
In the Landmarks app, a user can flag their favorite places, and filter the list to show just their favorites. To create this feature, you’ll start by adding a switch to the list so users can focus on just their favorites, and then you’ll add a star-shaped button that a user taps to flag a landmark as a favorite. Download the starter project and follow along with this tutorial, or open the finis..
-
Building Lists and Navigation 예제 정리SwiftUI/Document 예제 2020. 12. 18. 10:00
이전에 만든 Landmarks 앱에서 랜드마크 리스트와 각각의 위치를 보여주는 디테일 뷰를 추가해 볼 것이다. 각 랜드마크의 정보를 보여주는 뷰를 만들고 랜드마크를 보여주는 detail view를 볼 수 있는 scroll 가능한 리스트를 동적으로 만들어 볼 것이다. UI를 위해, 사이즈가 다른 device 들을 다수의 preview로 볼 것이다. 지금 보니 애플이 다운받으라는 프로젝트를 다운받아도 쓸건 이미지 밖에 없는 것 같다. 완성하면 나중에 지워도 될 것 같다, *참고 예제 : developer.apple.com/tutorials/swiftui/building-lists-and-navigation 위 예제를 보면서 진행해주세요 :) Section 1 Create a Landmark Model In ..
-
Offset과 Padding의 차이SwiftUI 2020. 12. 17. 10:00
Offset 정의 /// Offset this view by the specified horizontal and vertical distances. /// /// Use `offset(x:y:)` to to shift the displayed contents by the amount /// specified in the `x` and `y` parameters. /// /// The original dimensions of the view aren't changed by offsetting the /// contents; in the example below the gray border drawn by this view /// surrounds the original position of the text..
-
Introducing Swift UI 예제 정리SwiftUI/Document 예제 2020. 12. 16. 10:00
SwiftUI is a modern way to declare user interfaces for any Apple platform. Create beautiful, dynamic apps faster than ever before. 해석 : 스유는 애플 플랫폼을 위해 UI를 선언하는 현대적인 방법이다. 아름답고, 전래없이 빠른 동적 앱들을 창조해보세요. 생각 : 흠.. 역시 애플. 아름다움을 강조하는 구만. 근데 스유의 어떤게 아름다운진 모르겠다만 ㅋㅋ *애플 예제를 보면서 참고해주세요 :)* - 예제 링크 : developer.apple.com/tutorials/swiftui/creating-and-combining-views Creating and Combining Views This tutoria..
-
App Structure and Behavior 해석SwiftUI/Essential 2020. 12. 15. 10:00
App Structure and Behavior Define the entry point and top-level organization of your app. 앱의 진입점과 최상위 구조를 정의하라 Overview Declare your app by creating a structure that conforms to the App protocol and add one or more scenes to it. You can use built-in scenes, like WindowGroup, or you can compose custom scenes that conform to the Scene protocol. Scenes contain the view hierarchies that define the u..