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

标签 ios swift parse-platform notifications

我想检索类中对象的数量,然后在角标(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/

相关文章:

ios - Swift:如何在加载 View Controller X 次后创建事件

ios - MTOUCHTASK:错误MT2002更新为统一的API Xamarin表单

image - 从用户类快速解析中检索头像

ios - addUniqueObject 属性导致 xcode 中的编译器错误

ios - UINavigationController 在推送 View 后显示黑屏

ios - 使用 Swift 向 Google 应用引擎端点创建 REST 请求时出错

swift - 在 Swift 中将十六进制转换为十进制

ios - 导航器菜单从右侧滑入

ios - 一旦列表被删除,UITableView 将不会刷新。 self.tableView.reloadData() 也不起作用

php - 无法从对象 php 获取 parse.com 关系