我想要检索一个类中的对象数,然后在徽章上显示该数字。
问题是,如果我写self.totalMessagesInMesagesCount = count
我收到此错误:无法分配类型'Int32?'的值将该变量分配给applicationIconBadgeNumber
所以我有:
var totalMessagesInMesagesCount : Int!
然后:
//MARK: this requires permission for notifications
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil
))
//MARK: this sets the number displayed in the red badge
UIApplication.sharedApplication().applicationIconBadgeNumber = totalMessagesInMesagesCount
最后我想要检索数字并将其放在变量
中func loadMessagesByObjectData() {
var findTimeLineDataQuery = PFQuery(className: KeyWords.ParseClassForPublicMessages)
findTimeLineDataQuery.countObjectsInBackgroundWithBlock {
(count: Int32, error: NSError?) -> Void in
if error == nil {
print("there are \(count) messages")
self.totalMessagesInMesagesCount = //what? count is not working
}
}
}
提前致谢
答案 0 :(得分:0)
声音变量totalMessagesInMesagesCount
来自Int
类型,而变量count
属于Int32
类型。如此简单,通过这样的方式解决它:
self.totalMessagesInMesagesCount = Int(count)