2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-02-04

#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

2
2
0

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
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?