39

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: UIApplication,
    didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool 
{
    FBLoginView.self
    FBProfilePictureView.self
    return true
}

With error:

/Users/../AppDelegate.swift:14:11: Objective-C method 'application:didFinishLaunchingWithOptions:' provided by method 'application(:didFinishLaunchingWithOptions:)' conflicts with optional requirement method 'application(:didFinishLaunchingWithOptions:)' in protocol 'UIApplicationDelegate'

And second

func application(application: UIApplication,        
                            openURL url: NSURL,
                            sourceApplication: NSString?,
                            annotation: AnyObject) -> Bool {
    var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication as! String)
    return wasHandled
}

with error

/Users/../AppDelegate.swift:25:11: Objective-C method 'application:openURL:sourceApplication:annotation:' provided by method 'application(:openURL:sourceApplication:annotation:)' conflicts with optional requirement method 'application(:openURL:sourceApplication:annotation:)' in protocol 'UIApplicationDelegate'

I understand that most likely I should like you to stick together somehow these two functions into one. I do not understand why this code suddenly stopped working in 6.3, despite the fact that it worked in 6.2.

Cœur
  • 37,241
  • 25
  • 195
  • 267

5 Answers5

76

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.

Community
  • 1
  • 1
kbpontius
  • 3,867
  • 1
  • 30
  • 34
24

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
Renato Ignacio
  • 241
  • 2
  • 4
  • Thanks for pointing that out! It appears the changes were updated. – kbpontius Apr 17 '15 at 15:25
  • Thanks for the suggestion. It gave me a headache while trying to solve a number of issues while reading RayWenderlich's 'iOS8 by Tutorials v1.2' using Xcode-6.4 – iOS-Coder Aug 18 '15 at 15:33
5

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

Andrew
  • 3,733
  • 1
  • 35
  • 36
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Leo Correa May 07 '15 at 18:46
  • It does help answer the question. This error will happen when you use a NSString instead of a String. – Andrew May 07 '15 at 21:42
2

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

Isham
  • 424
  • 4
  • 14
0

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

Hope this helps!

Reoxy
  • 105
  • 1
  • 8