ios - Swift 2.0 - Binary Operator "|" cannot be applied to two UIUserNotificationType operands -


i trying register application local notifications way:

uiapplication.sharedapplication().registerusernotificationsettings(uiusernotificationsettings(fortypes: uiusernotificationtype.alert | uiusernotificationtype.badge, categories: nil)) 

in xcode 7 , swift 2.0 - error binary operator "|" cannot applied 2 uiusernotificationtype operands. please me.

in swift 2, many types typically have been updated conform optionsettype protocol. allows array syntax usage, , in case, can use following.

let settings = uiusernotificationsettings(fortypes: [.alert, .badge], categories: nil) uiapplication.sharedapplication().registerusernotificationsettings(settings) 

and on related note, if want check if option set contains specific option, no longer need use bitwise , and nil check. can ask option set if contains specific value in same way check if array contained value.

let settings = uiusernotificationsettings(fortypes: [.alert, .badge], categories: nil)  if settings.types.contains(.alert) {     // stuff } 

in swift 3, samples must written follows:

let settings = uiusernotificationsettings(types: [.alert, .badge], categories: nil) uiapplication.shared.registerusernotificationsettings(settings) 

and

let settings = uiusernotificationsettings(types: [.alert, .badge], categories: nil)  if settings.types.contains(.alert) {     // stuff } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -