I just have a Objective-C project and I want to use AppDelegate to access to my xcdatamodel, but when I add AppDelegate.swift
to my project it show me a compile problem, it is error because it doesn't know what AppDelegate use and what is the main. Then I tried to delete AppDelegate.h
and AppDelegate.m
and add AppDelegate.swift
, but it also doesn't work and still has compile errors.
How I can add AppDelegate.swift
to it?
Lets start with the Adding the swiftUI AppDelegate , Initially create a AppDelegate. swift file func application ( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [ UIApplication. LaunchOptionsKey: Any ]?) -> Bool { // Override point for customization after application launch.
Xcode has come up with the App instead of AppDelegate. We can add the AppDelegate in the App using the following method Known as Lets start with the Adding the swiftUI AppDelegate , Initially create a AppDelegate. swift file
Your app delegate object manages your app’s shared behaviors. The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system. Like the UIApplication object, UIKit creates your app delegate object early in your app’s launch cycle so it is always present.
If you want to use AppDelegate.swift
instead of AppDelegate.h
/ AppDelegate.m
, you should add the Swift file to your project and delete the .h
and .m
files (don't forget to click yes when asked about the bridging header). In addition, you should also delete main.m
since it is not needed anymore and will cause a linker error.
Teo is correct. To solve the main.m file compile problem add @UIApplicationMain above the class declaration
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
I recommend you to create a new Xcode project with Swift as default and check out the AppDelegate code in that one and copy/adapt it over to your project.
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