공식문서를 정리 했습니다.
Declare the user interface groupings that make up the parts of your app.
번역 ) 앱의 일부를 구성하는 사용자 인터페이스 그룹을 선언합니다.
A part of an app’s user interface with a life cycle managed by the system.
번역 ) 시스템에서 관리하는 수명 주기가 있는 앱 사용자 인터페이스의 일부입니다.protocol Scene
An indication of a scene’s operational state.
번역 ) Scene의 조작 상태 표시enum ScenePhase
@Environment(\.scenePhase) private var scenePhase
단계가 변할 때마다 동작을 실행시킬 수 있으며, Environment의 ScenePhase 값을 관찰하여 현재 단계를 읽습니다.
@main
struct MyApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
MyRootView()
}
.onChange(of: scenePhase) { phase in
if phase == .background {
// Perform cleanup when all scenes within
// MyApp go to the background.
}
}
}
}
struct MyScene: Scene {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
MyRootView()
}
.onChange(of: scenePhase) { phase in
if phase == .background {
// Perform cleanup when all scenes within
// MyScene go to the background.
}
}
}
}
struct MyView: View {
@ObservedObject var model: DataModel
@Environment(\.scenePhase) private var scenePhase
var body: some View {
TimerView()
.onChange(of: scenePhase) { phase in
model.isTimerRunning = (phase == .active)
}
}
}
A result builder for composing a collection of scenes into a single composite scene.
번역 ) Scenes 구성들을 하나의 단일 씬으로 바꾸는 result builder
A scene that presents a group of identically structured windows.
번역 ) 동일한 구조의 Windows를 보여주는 Scene
@main
struct Mail: App {
var body: some Scene {
WindowGroup {
MailViewer() // Declare a view hierarchy here.
}
}
}
그룹에서 생성된 각 Window는 View 계층에 의해 인스턴스화된 State 또는 StateObject 변수를 위한 새로운 저장소를 할당합니다.
예시) macOS 에서는 다음과 같이 다수의 윈도우를 개별 Scene으로 보여주거나, 탭으로 여러 Scene을 묶어서 보여줄 수 있습니다.
A scene that presents an interface for viewing and modifying an app’s settings.
번역 ) 앱의 세팅들을 보여주거나 수정하는 인터페이스를 나타내는 Scenestruct Settings<Content> where Content : View
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
#if os(macOS)
Settings {
SettingsView()
}
#endif
}
}