Develop/SwiftUI (14) 썸네일형 리스트형 [Combine] ObservableObject, @StateObject, @ObservedObject, @EnvironmentObject SwiftUI는 선언형 UI 프레임워크로, 데이터가 변경되면 뷰가 자동으로 업데이트되는 '데이터 바인딩'이 핵심입니다.String, Int 같은 값 타입(Struct, Enum)은 @State나 @Binding을 사용해 간단히 상태를 관리할 수 있습니다. 아래 포스팅에서 @State와 @Binding에 대한 내용이다. [SwiftUI] Managing user interface state이 문서의 글을 번역하여 글을 작성하였습니다. Managing user interface state | Apple Developer DocumentationEncapsulate view-specific data within your app’s view hierarchy to make your views reusable... [Combine] Combine (1) - Combine이란? 우리가 컴바인을 알아보기 전에 함수형 반응형 프로그래밍에 대하여 알아보자 반응형 프로그래밍이란?반응형 프로그래밍의 기본 개념은 모든 것이 이벤트이며, 이러한 이벤트는 비동기적으로 발생한다. 이벤트는 이벤트 소스에 의해 전송되며, 관심 있는 루틴에 특정 이벤트를 수신하도록 등록할 수 있다. 대부분의 경우 이러한 이벤트 스트림은 각 subscriber에게 더 유용하게 변환(transformed)한다. CombineCombine은 시간에 따라 값들을 처리하기 위한 선언형 문법 API이다. 아래는 주요 3가지 핵심 개념이다. Publisher값을 시간에 따라 전달하는 객체. completion하거나 error로 종료될 수 있다.ex) URLSession.DataTaskPublisher, Just, Notific.. TCA(The Composable Architecture) 다양한 아키텍처에 대하여 공부하는 중 Combine과 함께 작동하는 TCA에 대하여 포스팅해보려고 한다.내용은 아래 공식 깃헙 링크를 참고하였다. GitHub - pointfreeco/swift-composable-architecture: A library for building applications in a consistent and understandable way,A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind. - pointfreeco/swift-composable-architecturegithub.comTCA(The .. [SwiftUI] Managing user interface state 이 문서의 글을 번역하여 글을 작성하였습니다. Managing user interface state | Apple Developer DocumentationEncapsulate view-specific data within your app’s view hierarchy to make your views reusable.developer.apple.com 사용자 인터페이스(UI) 상태 관리앱의 View 계층 구조 내의 View 별 데이터를 캡슐화 하여 View를 재사용할 수 있도록 합니다.SwiftUI에서는 값을 수정하려면 Swift에서 처럼 body 내에서 값을 변경 할 수 없습니다.SwiftUI에서 데이터는 View의 최소 공통 조상에 상태로 저장되고 단일 진실의 출처를 제공합니다.이를 통해 데이터는.. [SwiftUI] GeometryReader GeometryReaderA container view that defines its content as a function of its own size and coordinate space.→ content의 고유한 Size와 좌표 공간의 함수로 정의하는 Container View→ 자식 뷰에 부모 뷰와 기기에 대한 크기 및 좌표계 정보를 전달하는 기능을 수행함GeometryReader{ _ in Circle().fill(Color.purple) .frame(width: 200, height: 200) .overlay(Text("Center").font(.title))}.background(Color.gray) GeometryProxy@available(iOS 13.0, .. [SwiftUI] List List하나의 열에 여러 개의 행으로 표현되는 UI를 구성해 다중 데이터를 쉽게 나열할 수 있는 구성된 ViewUIKit에서 동일한 역할을 하던 UITableView와 비교적 사용법이 간소화 됨List{ ForEach(0.. 동적 콘텐츠에서 사용 방식Range 동적 콘텐츠로 Range 타입을 넘겨줌Half-Open Range Operator(Range) A.. 다른 범위 연산자는 사용 불가List(0..RandomAccessCollection Protocol1. id로 사용할 값을 직접 인수로 지정// Hashable 프로토콜 준수 시에는 간편하게 self로 사용List(["A", "B", "C", "D", "E"], id: \.self){ Text("\($0)")} 2. Identifiabl.. [SwiftUI] Button Button 액션을 시작하는 가장 기본적인 컨트롤 UIKit의 UIButton과 같은 역할 기본적인 Button의 선언 Button(action: { // 버튼 액션 }){ Text("버튼") // Button Title } Button 사용 HStack(spacing: 20){ // 첫 번째 버튼 Button("Button"){ print("Button1") } // 두 번째 버튼 Button(action: { print("Button2") }){ Text("Button") .padding() .background(RoundedRectangle(cornerRadius: 10.0).strokeBorder()) } // 세 번째 버튼 Button(action:{print("Button3")}){ Circl.. [SwiftUI] 공식문서 파헤치기 (3) [Spacer / Divider] Spacer Spacer | Apple Developer Documentation A flexible space that expands along the major axis of its containing stack layout, or on both axes if not contained in a stack. developer.apple.com 주축을 포함하는 Stack Layout에서 팽창하거나 Stack 안에서 두 축 위에 포함되지 않는 유연한 빈 공간 Spacer는 뷰와 대응하여 내용 없이 최대로 팽창하며 생성할 수 있습니다. 아래는 Spacer를 활용한 예시 코드입니다. 1. Spacer를 사용하기 전의 코드 struct ChecklistRow: View { let name: String var .. 이전 1 2 다음