반응형
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
- RxCocoa
- graphql
- ios14
- Bug
- nonisolated
- RxSwift
- init
- IOS
- SWIFT
- SwiftUI
- dismiss
- nestjs
- @EnvironmentObject
- @State
- URL(string:)
- Creating Operators
- RFC1738/1808
- swift6
- vim
- NavigationLink
- typeorm
- @Environment
- operator
- Operater
- Xcode
- Operators
- NullObject
- @Binding
- init?
- subject
Archives
- Today
- Total
Tunko Development Diary
[iOS][SwfitUI] SwiftUI life cycle에서 AppDelegate사용하기 본문
Fierbase 등 프레임워크를 초기화해야 되는데 AppDelegate에서밖에 할 수 없는 상황이 나온다.
이때는 아래 코드로 처리하면 된다.
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.")
return true
}
}
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
이 방법을 사용하는 이유는 일반적인 이니셜라이저로 초기화가 안되기 때문이다.
아래 코드는 불가능한 방법이다.
@main
struct TestApp: App {
init() {
FirebaseApp.configure() // 불가능
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
참조 : stackoverflow
반응형
'Development > iOS 개발' 카테고리의 다른 글
[iOS][SwiftUI] Spacer 정리 (0) | 2021.02.15 |
---|---|
[iOS][SwiftUI] VStack, HStack, ZStack 정리 (0) | 2021.02.15 |
[iOS14][SwfitUI] SwiftUI2 life cycle 에서 딥링크 처리 (0) | 2021.02.14 |
[iOS14][SwfitUI] SwiftUI2 App life cycle 정리 (0) | 2021.02.14 |
[iOS][swiftUI] iOS13에서 분할된 AppDelegate와 추가된SceneDelegate이해하기 (0) | 2021.02.13 |
Comments