计算Parse类中的对象数并将其分配给变量

时间:2015-10-22 23:16:57

标签: ios swift parse-platform notifications

我想要检索一个类中的对象数,然后在徽章上显示该数字。

问题是,如果我写self.totalMessagesInMesagesCount = count我收到此错误:无法分配类型'Int32?'的值将该变量分配给applicationIconBadgeNumber

时,将值设置为“Int”

所以我有:

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

            }
        }


    }

提前致谢

1 个答案:

答案 0 :(得分:0)

声音变量totalMessagesInMesagesCount来自Int类型,而变量count属于Int32类型。如此简单,通过这样的方式解决它:

    self.totalMessagesInMesagesCount = Int(count)