gpt4 book ai didi

ios - 计算解析类中的对象数量并将其分配给变量

转载 作者:行者123 更新时间:2023-11-30 13:58:30 25 4
gpt4 key购买 nike

我想检索类中对象的数量,然后在角标(Badge)上显示该数字。

问题是,如果我写 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

}
}


}

提前致谢

最佳答案

听起来变量 totalMessagesInMesagesCount 来自类型 Int,而变量 countInt32 类型。很简单,通过像这样的转换来解决它:

    self.totalMessagesInMesagesCount = Int(count)

关于ios - 计算解析类中的对象数量并将其分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33292358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com