2

I hope someone can guide me...I know Swift 2.0/ Xcode 7 still in beta but I need to convert my code... Here is my code...

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        let notification:CKNotification = CKNotification(fromRemoteNotificationDictionary: userInfo)
        //application.applicationIconBadgeNumber = 0
        if (notification.notificationType == CKNotificationType.Query) {
            let queryNotification = notification as! CKQueryNotification
            let recordID = queryNotification.recordID
            receivedRecord = recordID
            NSNotificationCenter.defaultCenter().postNotificationName("updateDatabase", object: nil)
        }
    }

So the expected Dict for CKNotification has changed to [String:NSObject] -> before was [NSObject:AnyObject] which conformed to the returned Dict! and the returned Dict from the function(didReceiveRemoteNotification) is: [NSObject : AnyObject]

Taken from Xcode 7 -> public convenience init(fromRemoteNotificationDictionary notificationDictionary: [String : NSObject])

Taken from Xcode 6.4 -> convenience init!(fromRemoteNotificationDictionary notificationDictionary: [NSObject : AnyObject]!)

So, my question is, how could I convert this or do I miss something obvious? Might this be a bug?

Thanks for any guidance/ help...

Armin Scheithauer
  • 601
  • 1
  • 7
  • 17
  • My tip for updating methods whose signature has changed: don't modify the one you have in place, instead, start typing the method call on another line and Xcode will auto-suggest the new signature; then you just have to adapt and edit. – Eric Aya Aug 25 '15 at 11:11
  • I tried that but there was no suggestion from Xcode in that case, I already tried a lot and asking here was the last option.... – Armin Scheithauer Aug 25 '15 at 11:13

1 Answers1

2

Do this:

if let userInfo = userInfo as? [String: NSObject] {
    let notification = CKNotification(fromRemoteNotificationDictionary: userInfo)
    ...
    ...
}
fantaghirocco
  • 4,761
  • 6
  • 38
  • 48