Objective-C method conflicts with optional requirement method Swift

前端 未结 5 1103
走了就别回头了
走了就别回头了 2020-12-13 03:59

After the Xcode update, the compiler began to throw an error on the working code (both functions are in the AppDelegate.swift).

func application(application:         


        
相关标签:
5条回答
  • 2020-12-13 04:35

    You should also make sure you are using the correct type. Use String instead of NSString.

    0 讨论(0)
  • 2020-12-13 04:40

    Try overriding that method again from Xcode completions. Worked for me.

    0 讨论(0)
  • 2020-12-13 04:44

    The type of the launchOptions parameter of the didFinishLaunchingWithOptions function was changed in XCode 6.3:

    "launchOptions: NSDictionary?" has become "launchOptions: [NSObject: AnyObject]?"

    Just change your function header to match the following:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
    
    0 讨论(0)
  • 2020-12-13 04:49

    launchOptions have been changed; try changing out "launchOptions: NSDictionary?" to "launchOptions: [NSObject: AnyObject]?"

    Hope this helps!

    0 讨论(0)
  • 2020-12-13 04:51

    I'm not sure exactly why the compiler is throwing the error, however I do see a difference in the default Swift version of those same methods. Perhaps you could replace the function declaration with those created with a normal Swift project:

    1

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool

    2

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool

    I'd recommend replacing your method declarations with the above to see if it compiles now.


    EDIT 1 (9/21/2015): I've confirmed these are now up to date for Xcode 7's public release. They removed the optional (annotation: AnyObject?) and made it (annotation: AnyObject), in declaration #2.

    0 讨论(0)
提交回复
热议问题