I like to know why we should create and use a SwiftUI Interface with UIKit Life Cycle? I get confused about it! Because:
1-if you want UIKit programming then go and choose Storyboard for Interface and then choose UIKit for Life Cycle.
2-if you want SwiftUI programming then go and choose SwiftUI for Interface and then choose SwiftUI for Life Cycle.
3-if you want change your Swift Language then go change it to Objective-C and you will get Storyboard as Interface and UIKit as Life Cycle.
Here comes Option 4:
4- You can have SwiftUI for Interface and UIKit as life Cycle! which is the Topic of this Question! If I am not wrong SwiftUI handle things different than UIKit, we do not need define delegate or protocols in SwiftUI or things like that, but why we get AppDelegate and SceneDelegate in this case! what is pros and cons in case we create such a Xcode project?
SwiftUI is limited and works better with iOS 14 and iOS 15. On the contrary, UIKit enables you to support even iOS version 9.0. This makes UIKit more flexible. It surely wins against SwiftUI when it comes to backward compatibility.
The hosting controller is compatible with UIKit since it is a subclass of UIViewController . The purpose of the UIHostingController is to enclose a SwiftUI view so that it can be integrated into an existing UIKit based project.
It's an iOS app's “main” function, the first one called during the lifetime of the app. You typically use it for: Initial configuration of 3rd-party components and frameworks, such as setting up Firebase, Bugsnag, Realm, OneSignal, Parse Server, Reachability services, and so on.
Does SwiftUI replace UIKit? No. Many parts of SwiftUI directly build on top of existing UIKit components, such as UITableView .
With SwiftUI you should in most cases use SwiftUI lifecycle.
If you need some AppDelegate methods you can use @UIApplicationDelegateAdaptor
:
There are some cases, however, when you need UIKit lifecycle:
SceneDelegate
(see Is there any way to call SceneDelegate methods in iOS 14 app life cycle?)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With