일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- 문법
- Xcode
- tuist
- Architecture
- GIT
- raspberrypi5
- flutter
- OpenAI
- weatherkit
- philipshue
- isolate
- builder
- embedded-swift
- iot
- SwiftUI
- dart
- URLSession
- swift
- LifeCycle
- dgcharts
- AppleDeveloper
- chartsorg
- uikit
- dartz
- WWDC24
- SampleApp
- network
- EventLoop
- WebSocket
- designpattern
Archives
- Today
- Total
Jaebi의 Binary는 호남선
SwiftUI - App Protocol 본문
목차 Open
App
- 앱의 구조와 동작을 나타내는 Protocol
- app의 content를 정의하는
body
computed property 필요 @main
annotation으로 entry point 지정 → 모든 app file에는 하나의 entry pointbody
→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 |