Tony Merritt Tony Merritt - 2 months ago 19
iOS Question

change to private or @nonobjc

I am working on a tutorial that is creating an social media type app. I am using Firebase and have implemented all the things needed from there guides, all is working except this code below.

It is saying there is an error and asking to fix, but making it private or adding @nonobjc.

This is my code:

func application(_ application: UIApplication, open url: URL, sourceApplication: String, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}


There is a version of code on the Firebase site but it is in Objective C:

- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

return handled;
}


Hope this helps and makes sense.

Rob Rob
Answer

Generally, warnings about app delegate methods needing to be changed to private or @nonobjc is an indication that an app delegate method signature is not correct. Consider:

func application(_ application: UIApplication, open url: URL, sourceApplication: String, annotation: AnyObject?) -> Bool {
    ...
}

This has been replaced with:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    ...
}

And, according to the UIApplicationDelegate protocol definition, as of iOS 9, the this has been marked deprecated in favor of:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    ...
}

This last rendition corresponds most closely to that Objective-C code sample you shared with us.