일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- AppleDeveloper
- isolate
- dgcharts
- uikit
- Xcode
- 문법
- EventLoop
- dart
- tuist
- state
- philipshue
- designpattern
- SampleApp
- SwiftUI
- realtime
- OpenAI
- GIT
- Architecture
- chartsorg
- iot
- network
- builder
- dartz
- WebSocket
- weatherkit
- WWDC24
- flutter
- swift
- LifeCycle
- concurrency
Archives
- Today
- Total
Jaebi의 Binary는 호남선
SwiftUI - App Protocol 본문
목차
App
- 앱의 구조와 동작을 나타내는 Protocol
- app의 content를 정의하는 `body` computed property 필요
- `@main` annotation으로 entry point 지정 → 모든 app file에는 하나의 entry point
- `body` → `Scene` 프로토콜을 준수하며 각 scene은 view hierarchy의 rootview와 lifecycle을 가지고 있음
- 여기서 모든 scene에서 공유할 수 있는 state를 선언 할수 있음
- `@StateObject` / `@ObservedObject` attribute로 model을 만들고 view input으로 `ObservedObject`, 또는 `EnvironmentObject`로 scene에 넣을수 있음
- 예시:
@main
struct MyApp: App {
@StateObject private var sharedModel = SharedModel()
var body: some Scene {
WindowGroup {
RootView()
.environmentObject(sharedModel)
}
}
}
- `@main`, `App`, `Scene`, `WindowGroup`다 SwiftUI 앱의 Lifecycle과 관련이 있음
Reference
App | Apple Developer Documentation
A type that represents the structure and behavior of an app.
developer.apple.com
'Swift' 카테고리의 다른 글
AppDelegate & SceneDelegate (0) | 2024.07.21 |
---|---|
App Lifecycle (0) | 2024.07.21 |
ARC (Automatic Reference Counting) (0) | 2024.07.20 |
Swift - Memory 기초 (0) | 2024.07.20 |
Swift - 문법 (접근 제어) (0) | 2024.07.20 |