ios - 如何使用 Swift 从 Parse 中的 _User 类获取 currentUserInfo

标签 ios swift parse-platform

我尝试过这个:

var data:NSMutableArray = NSMutableArray()

func loadData() {
    var userQuery = PFUser.query()!
    userQuery.whereKey("objectId", equalTo: PFUser.currentUser()!.objectId!)
    userQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
       if let objects = objects {
          for object in objects  {
              self.data.addObject(object)
          }
       }
    }
    println(data) // this gives an empty NSMutableArray.
}

还有其他方法可以获取当前用户的数据吗? ,我这样做是为了制作当前用户的个人资料屏幕..感谢您的时间..

最佳答案

使用它来访问当前用户

if PFUser.currentUser() != nil {
    PFUser.currentUser()!.fetchIfNeededInBackgroundWithBlock({ (user: PFObject?, error: NSError?) -> Void in
        if user != nil {
            var u = user as! PFUser
            //Access the fetched user HERE
         }
    })
    //NOT here, it will be nil here
}

关于ios - 如何使用 Swift 从 Parse 中的 _User 类获取 currentUserInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034467/

相关文章:

ios - 谷歌地方信息 API : Is it possible to specify the establishment (using the filter)

iOS 启动画面图像未复制

ios - (ios10.2)(swift3) 如何判断用户是否点击了本地通知?

ios - 在 tableview 中使用 parse.com 图片时出错

ios - 解析数据未出现在 iOS 9 Beta 4 中

ios - Swift:属性未在 super.init 调用时初始化

swift 2 : Why doesn't this Dictionary extension compiles?

ios - 如何使用蒙版为圆形图像添加边框

ios - Swift - 将 SKScene 叠加到 UIView 上 - 灰色背景

ios - 在 Swift 中子类化 Parse 的 PFUser