0

This is the code given to me in Swift:

 if application.respondsToSelector("registerUserNotificationSettings:") {
        let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
        let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound
        application.registerForRemoteNotificationTypes(types)
    }

I receive an error at line two telling me:

| is not a prefix unary operator

What does that mean?

I also receive an error at line 7 telling:

Binary Operator | cannot be applied to UIRemoteNotificationType

Can someone help me get a better understanding on this? I'm clueless on what's going on.

KTPatel
  • 1,212
  • 4
  • 19
  • 24
Amit Kalra
  • 4,085
  • 6
  • 28
  • 44
  • [Here](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html) is the link for the Swift Unary Operator documentation. [Here is a post that also will help you](http://stackoverflow.com/questions/30761996/swift-2-0-binary-operator-cannot-be-applied-to-two-uiusernotificationtype) – Max Worg Oct 10 '15 at 03:28

1 Answers1

0

In iOS 9, apple doesn't give you that option to use | , what you need to do is to group the [.Bagde ,.Alert, .Sound] into a sort of array

Just change this line

 let types = UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound

 let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound

To

  let types = [.Badge,.Alert ,.Sound] 
 let userNotificationTypes =  [.Alert ,.Badge ,.Sound]
Lamour
  • 3,002
  • 2
  • 16
  • 28