せっかくiOSアプリをSwiftで書けるようになったのに、Objective-Cのスニペットが多すぎる!
ということで、私が変換したSwiftコードを貼り付けていくシリーズです。
Xcode 7.1, Swift2.1で確認しています。
元ネタはこちら
バッジ数をリセットしたい #52
https://github.com/NIFTYCloud-mbaas/UserCommunity/issues/52
func updateBadgeNumber(number : Int) {
if ( number < 1 ) {
UIApplication.sharedApplication().applicationIconBadgeNumber = -1
} else {
UIApplication.sharedApplication().applicationIconBadgeNumber = number
}
let currentInstallation = NCMBInstallation.currentInstallation()
if (currentInstallation.deviceToken == nil) {
return
}
// installation class update
currentInstallation.setObject(number, forKey: "badge")
currentInstallation.saveInBackgroundWithBlock{(error) -> Void in
if ((error == nil)) {
print("updateBadgeNumber complete")
} else {
print("updateBadgeNumber error: \(error)")
}
}
}