ios - 使用 "_User"从 Parse "ObjectId"类中检索用户数据

标签 ios swift parse-platform

我正在尝试检索用户数据以使用对象 ID 从 _User 类获取用户信息。我用过这个:

var data:NSMutableArray = NSMutableArray()
func loadData() {
    data.removeAllObjects()

    var profileQuery:PFQuery = PFUser.query()!
        profileQuery.getObjectInBackgroundWithId(userId, block: { (objects, error) -> Void in
            if error == nil {
                self.data.addObject(objects!)
            }
        })
    println(userId) // this is the userId as String.
    println(self.data)  ********* // empty array.
}

我在这里得到一个空数组data..我也试过了,但同样的事情也发生在这里。 :

 var profileQuery:PFQuery = PFUser.query()!
        profileQuery.whereKey("objectId", equalTo: userId)
        profileQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
            if let objects = objects {
                for object in objects {
                    self.data.addObject(object)   
                }   
            }
        }

最佳答案

请记住,“findObjectsInBackgroundWithBlock”是异步发生的!您需要将与数据相关的任何逻辑放入 block 内。

var profileQuery:PFQuery = PFUser.query()!
profileQuery.getObjectInBackgroundWithId(userId, block: { (objects, error) -> Void in
    if error == nil {
        self.data.addObject(objects!)
        println(self.data) //shouldn't be empty.
    }
})

关于ios - 使用 "_User"从 Parse "ObjectId"类中检索用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32215257/

相关文章:

ios - 从 TableView 中删除单元格

ios - 如何使用和调试不存在模拟器的 iOS 版本?

swift - 编译器错误: Invalid library file - CoreLocation

swift - 直播流中的 AVPlayer 音频缓冲

javascript - 为什么 Parse 不在下面的 _.each 循环中按顺序保存对象?

parse-platform - 如何将 Parse.Promise 与其他形式的 Promise 混合使用,例如Bluebird/ES6 原生 promise ?

ios - 如何将 UITableCellView 中的 imageView 属性设置为仅显示背景颜色?

ios - 如何使用for循环从具有多个变量的数据库中获取值?

ios - 了解 Parse Geopoint 和 CoreLocation 之间的区别

ios - 出现通知横幅时设备方向不正确