search
LoginSignup
2

More than 3 years have passed since last update.

posted at

updated at

[Swift]Swift2.0からUIUserNotificationTypeのoption設定が変わった

UIUserNotificationTypeの"|"でエラーした

Swift1.2まではUIUserNotificationTypeのoption設定は"|"で区切ることによって複数設定していた。が、Swift2.0に更新したらerrorが発生しちゃった。
どうやらUIUserNotificationTypeの型がRawOptionSetType(Bit演算可能)からOptionSetType(Bit演算不可能)に変更されたのが原因らしい。

・Swift1.2 ver

AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    application.registerUserNotificationSettings(
        UIUserNotificationSettings(forTypes:
            UIUserNotificationType.Sound
              | UIUserNotificationType.Badge
              | UIUserNotificationType.Alert
            , categories: nil))

    return true
}

error: Binary Operator "|" cannot be applied to two UIUserNotificationType operands

・Swift2.0 ver

AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    application.registerUserNotificationSettings(
        UIUserNotificationSettings(forTypes:
            [UIUserNotificationType.Sound,
                UIUserNotificationType.Badge,
                UIUserNotificationType.Alert]
            , categories: nil))

    return true
}

これでO.K.

参考URL

StackOverFlow: http://stackoverflow.com/questions/30761996/swift-2-0-binary-operator-cannot-be-applied-to-two-uiusernotificationtype
Toyship.org: http://www.toyship.org/archives/2208

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
2