Enrico Susatyo
Enrico Susatyo

Reputation: 19790

How do I implement delegate methods through Swift extension

My project is a mix of Obj-C and Swift, and I'm trying to extend my AppDelegate class with Swift.

So right now I have AppDelegate.m, AppDelegate.h, and AppDelegate.swift. Most of the methods are in the Obj-C file, but I'm trying to implement just one of the methods:

extension AppDelegate {

    func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {

    }
}

However it's complaining:

AppDelegate.swift:11:10: Method 'application(_:continueUserActivity:restorationHandler:)' with Objective-C selector 'application:continueUserActivity:restorationHandler:' conflicts with previous declaration with the same Objective-C selector

Is this a limitation of Swift extension? Or is there a way to implement this delegate method in my Swift extension file?

Upvotes: 2

Views: 2171

Answers (1)

Damian Rzeszot
Damian Rzeszot

Reputation: 555

You cannot do something like that. AppDelegate has defined this method (UIApplicationDelegate protocol says so).

The simplest solution would be to rewriteAppDelegate in swift.

You have also more difficult solution - remove UIApplicationDelegate from your AppDelegate and implement this protocol in your extension. It may raise unexpected errors if your AppDelegate is considerable size.

Upvotes: 4

Related Questions