Skip to content

Latest commit

 

History

History
68 lines (47 loc) · 2 KB

3.SwiftUI_LifeCycle.md

File metadata and controls

68 lines (47 loc) · 2 KB

🔷 SwiftUI LifeCycle

👉 View

  • Views are important because each of you define individually images or pieces of text are views to the horizontal or vertical scrolling containers

  • They can be composed together to form more complex user interfaces.

👉 Scenes

  • Views form the content of scenes allowing them to be independently displayed by their platform. Those scenes can also be composed together to form more complex scenes.

image

👉 Window Group

  • The Window Group scene manages the views though that are onboarding View render into. It can also create additional windows within the same window

image

👉 @AppStorage

  • It needs to store its state value using a permanent storage on the device fot this functionality. To use wrapper @AppStorage to store state data even closing application.

image

//  FruitsDic-App

import SwiftUI
@main
struct FruitsDic_AppApp: App {
	// MARK: -  APPStorage
	@AppStorage("isOnboarding") var isOnoarding: Bool = true

	var body: some Scene {
		WindowGroup {
			if isOnoarding {
				OnboardingView()
			} else {
				ContentView()
			}
		}
	}
}

👉 onboarding button action

//  StartButtonView.swift

import SwiftUI

struct StartButtonView: View {
	// MARK: -  PROPERTY
	// isOnboarding 을 optional 로 받아야 함
	@AppStorage("isOnboarding") var isOnboarding: Bool?

	// MARK: -  BODY
	var body: some View {
		Button(action: {
			// false 로 바꾸게 되면 @main 에서 설정한 대로 ContentView 로 이동
			isOnboarding = true
		}) {

스크린샷