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
Post a Comment