tutorial 6

[iOS App Dev Tutorials] SwiftUI - Passing Data (2)

Apple Developer Documentation developer.apple.com Section 3. Pass the Edit View a Binding to Data struct DetailEditView: View { @Binding var data: DailyScrum.Data ... } struct DetailEditView_Previews: PreviewProvider { static var previews: some View { DetailEditView(data: .constant(DailyScrum.sampleData[0].data)) } } DetailView에서 State 변수를 받기 위해 Binding으로 data 를 선언한다. struct DetailView: View { @..

[iOS App Dev Tutorials] SwiftUI - Navigation and Modal Presentation (3)

Apple Developer Documentation developer.apple.com 3. Creating the Edit View Section 1. Update the Data Model struct Data { var title: String = "" var attendees: [Attendee] = [] var lengthInMinutes: Double = 5 var theme: Theme = .seafoam } var data: Data { Data(title: title, attendees: attendees, lengthInMinutes: Double(lengthInMinutes), theme: theme) } } 아래 data는 DailyScrum의 속성 값을 받고 계산된 데이터를 반환..

[iOS App Dev Tutorials] SwiftUI - Navigation and Modal Presentation (2)

Apple Developer Documentation developer.apple.com 2. Managing Data Flow Between Views @State, @Binding 을 사용하여 사용자 인터페이스가 앱 데이터의 현재 상태를 반영하도록 한다. Source of Truth 정보의 여러 복사본을 관리하면 앱에서 버그를 유발할 수 있다. 따라서 각 데이터 요소에 대해 단일화 한다. 단일 데이터 요소(단일 진실 소스)를 한 곳에 저장하면, 다른 뷰가 동일한 데이터에 액세스 할 수 있다. 데이터를 어디에 저장하는지 정의하는 것은 다양한 뷰에서 공유하는지, 데이터가 변화하는지에 따라 달라진다. Swift Property Wrappers SwiftUI는 @State, @Binding 속성 래퍼를 사용..

[iOS App Dev Tutorials] SwiftUI - Navigation and Modal Presentation (1)

Apple Developer Documentation developer.apple.com 1. Creating a Navigation Hierarchy Section 1. Set Up Navigation @main struct ScrumdingerApp: App { var body: some Scene { WindowGroup { NavigationView { ScrumsView(scrums: DailyScrum.sampleData) } } } } struct ScrumsView: View { let scrums: [DailyScrum] var body: some View { List { ForEach(scrums) { scrum in NavigationLink(destination: Text(scrum..

[iOS App Dev Tutorials] SwiftUI - Views

Apple Developer Documentation developer.apple.com 1. Creating a Card View Color SwiftUI 프레임 워크는 View의 인스턴스로서 color를 다룬다. 에셋 카탈로그와 이름을 같게 enum을 만들어준다. accentColor는 해당 색의 보색으로 강조할 수 있게 만들어 주는 색이다. 그 색에 맞게 하얀색과 검정색을 반환한다. 메인 칼라 함수를 써서 enum의 rawValue를 Color 타입에 넣어 초기화를 한다. View의 background에 theme의 mainColor로 초기화하는 모습 LabelStyle SwiftUI에서 제공하는 LabelStyle 프로토콜을 사용해서 앱 전체에서 일관된 스타일의 레이블을 사용할 수 있게 한다. 여..