I'm trying to slowly migrate from Obj-C to Swift. My first step is to migrate small, simple methods to Swift extensions so I decided to try and migrate didRegisterForRemoteNotifications but that didn't work because it thinks the method is implemented somewhere else in my Objective-C code. It is not.
I'm using Xcode 7.3 (7D175)
Here's some reproduction steps:
- Create a new Obj-C project.
- Create a new empty Swift file called
AppDelegate-Extension.swift. This also creates a Bridging header file. - Add
#import AppDelegate.hto the Briding header file. Go to the empty Swift file and type:
extension AppDelegate { public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { } }
This causes to compiler to complain:
method 'application(_:didRegisterForRemoteNotificationsWithDeviceToken:)' with Objective-C selector 'application:didRegisterForRemoteNotificationsWithDeviceToken:' conflicts with previous declaration with the same Objective-C selector public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { ^ __ObjC.AppDelegate:38:17: note: 'application' previously declared here public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
What am I doing wrong?
EDIT: Some suggestions that I've tried:
Add
overrideto the method declaration so it readsoverride public ...
This returns the following error (in addition to the original error)
error: method does not override any method from its superclass override public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)