我想检索类中对象的数量,然后在角标(Badge)上显示该数字。
问题是,如果我写 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
}
}
}
提前致谢
最佳答案
听起来变量 totalMessagesInMesagesCount
来自类型 Int
,而变量 count
是 Int32
类型。很简单,通过像这样的转换来解决它:
self.totalMessagesInMesagesCount = Int(count)
关于ios - 计算解析类中的对象数量并将其分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33292358/