简体   繁体   中英

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?

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

The simplest solution would be to rewrite AppDelegate 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM