Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- IOS
- Architecture
- swiftconcurrency
- mainrunloop
- swift-demangle
- modulararchitecture
- swift6
- applaucnchprocess
- ios바이너리분석
- Xcode
- displayscale
- XCUITest
- Swift
- uicollectionview
- updatecycle
- swift6.1
- UIKit
- 이진삽입정렬
- mach-o파일분석
- cgimage
- mangle
- task
- WWDC24
- 다이나믹링크분석
- actor
- 뷰를그리는메서드
- xcrun swift-demangle
- 뷰의레이아웃을계산하는메서드
- ciimage
- SPM
Archives
- Today
- Total
꾸준한 기록
[SwiftUI] 기초 (App, Scene) 본문
import SwiftUI
@main
struct LandmarksApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
- SwiftUI App은 App 프로토콜을 준수하는 struct를 갖는다.
- @main와 함께 사용 ➡️ 앱의 시작점에 해당
- 앱에서 보여줄 컨텐츠를 갖는 Scene을 return 한다.
App

- 앱의 동작과 구조를 표현하는 타입
- 시스템에서 앱을 실행시킬 때 main() 메서드를 호출한다. App 프로콜이 main()의 default 구현을 제공
- 앱의 entry 포인트(시작점)은 한군데여야 함 ➡️ @main 한번만 사용 가능
Scene
- UI를 구성하는 view를 갖는다.
- 라이프사이클을 갖는다.
- 시스템이 라이프사이클 관리 ➡️ 시스템에서 view 계층을 언제, 어떻게 보여줄지를 결정한다.
- SwiftUI에는 Scene의 구체 타입을 제공함 (ex: WindowGroup). Custom Scene 생성 가능
@main
struct Mail: App {
@StateObject private var model = MailModel()
var body: some Scene {
WindowGroup {
MailViewer()
.environmentObject(model) // Passed through the environment.
}
Settings {
SettingsView(model: model) // Passed as an observed object.
}
}
}
- App에서 생성한 State는 여러 Scene에서 공유해서 사용할 수 있다.
- Stateobject를 사용해서 dataModel을 선언하고, ObservedObject로서 다른 뷰에 전달하거나, EnvironmentObject로 선언하여 environment를 통해서 전달할 수 있다.
Scene 라이프사이클 관리
struct MyScene: Scene {
@Environment(\.scenePhase) private var scenePhase
// ...
}
- Scene의 상태 확인 방법 - scenePhase
'iOS' 카테고리의 다른 글
| iOS 시스템의 메모리 구조 (0) | 2024.08.31 |
|---|---|
| [WWDC24] Bring you app's core features to with App Intents 요약 (0) | 2024.06.20 |
| Application State (1) | 2024.05.01 |
| FileSystem, FileManager (1) | 2023.10.25 |
| [iOS] URL Loading System (0) | 2022.08.11 |