parse.com swift return 查询后来自 class 的值
parse.com swift return values from class after query
我在解析中有第二个 class,其中每一行都链接到用户并存储一个整数。这已经设置好了。
现在我想检查当前用户并获取保存的 int 并将其放入标签中。有什么想法吗?
您将需要使用约束进行查询 ("meaning that get data only for the currentUser")。然后你有两个选项来检索他们的数据,或者使用 getfirstobjectinbackgroundwithblock() method
这将从解析中获取至少一行数据。或者使用 findObjectsInBackgroundWithBlock() method
将 return 来自解析的多行。
if in parse, the user is being saved as pointer use that line:
let userT = PFUser.CurrentUser() //<-- to get CurrentUser
if in parse, the user is being saved as string use that line
let userT = PFUser.CurrentUser().username //<-- to get CurrentUser
在这段代码中,我使用了 getFirstObjectInBackgroundWithBlock
方法,因为我认为你只向用户展示了一种东西,所以如果我错了,请使用第二种方法 findObjectsInBackgroundWithBlock
let query = PFQuery(className:"whateverNameYourClassIs")
let userT = PFUser.CurrentUser() //<-- to get CurrentUser
query.whereKey("NameOfUserColummInParse" equalTo:userT!)
query.getFirstObjectInBackgroundWithBlock { (object: PFObject?, error: NSError?) -> Void in
if error == nil
{
if let retreiveObject = object
{
let data = retreiveObject["IntValue"] as! Int //<-- IntValue supposed to be the name of your class column in parse where you want to retrieve the value.
}
}
})
我在解析中有第二个 class,其中每一行都链接到用户并存储一个整数。这已经设置好了。
现在我想检查当前用户并获取保存的 int 并将其放入标签中。有什么想法吗?
您将需要使用约束进行查询 ("meaning that get data only for the currentUser")。然后你有两个选项来检索他们的数据,或者使用 getfirstobjectinbackgroundwithblock() method
这将从解析中获取至少一行数据。或者使用 findObjectsInBackgroundWithBlock() method
将 return 来自解析的多行。
if in parse, the user is being saved as pointer use that line:
let userT = PFUser.CurrentUser() //<-- to get CurrentUser
if in parse, the user is being saved as string use that line
let userT = PFUser.CurrentUser().username //<-- to get CurrentUser
在这段代码中,我使用了 getFirstObjectInBackgroundWithBlock
方法,因为我认为你只向用户展示了一种东西,所以如果我错了,请使用第二种方法 findObjectsInBackgroundWithBlock
let query = PFQuery(className:"whateverNameYourClassIs")
let userT = PFUser.CurrentUser() //<-- to get CurrentUser
query.whereKey("NameOfUserColummInParse" equalTo:userT!)
query.getFirstObjectInBackgroundWithBlock { (object: PFObject?, error: NSError?) -> Void in
if error == nil
{
if let retreiveObject = object
{
let data = retreiveObject["IntValue"] as! Int //<-- IntValue supposed to be the name of your class column in parse where you want to retrieve the value.
}
}
})