ios swift parse:从3个类中收集数据 [英] ios swift parse: Collect data from 3 classes
问题描述
我有这样的结构:
- 用户
- CardSet,其指针"user"指向User.objectId,col为名称"
- 具有指向CardSet.objectId的指针"cardset"和col名称"的卡
我想选择所有卡数据,包括currentUser的CardSet名称.我在这里很迷失,因为我是新来的解析和敏捷者,并且不知道如何真正完成这项工作.
I would like to select all card data including the name of the CardSet for the currentUser. I am quite lost here as I am new to parse and swift and don't know really how to get this done.
我检查了文档并了解我必须包含
I checked the docs and understand I have to include
var query = PFQuery(className: "Card")
query.includeKey("cardset")
获取卡片组对象. 我没有得到的是如何仅选择当前用户的数据?
to get the cardset object. What I don't get is how to select the data only for the current user?
最后,如何将所有数据放入数组以用于表视图并将数据输出到其表单元格标签?
And at the end, how to get all data into an Array to use it for a table view and output the data to its table cell labels?
这是我到目前为止所拥有的:
This is what I have so far:
var noteObjects: NSMutableArray! = NSMutableArray()
func fetchAllObjects(){
var query = PFQuery(className: "Card")
query.includeKey("cardset")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if (error == nil){
var temp: NSArray = objects as NSArray
self.noteObjects = temp.mutableCopy() as NSMutableArray
self.tableView.reloadData()
}else{
println(error.userInfo)
}
}
println(self.noteObjects)
}
推荐答案
您的数据模型是明智的,但要解决它,则需要更复杂的查询.若要获取Cards
用户是当前用户的Cards
,必须在Card查询中嵌入CardSet查询.做到这一点的方法是whereKey:matchesQuery:
Your data model is sensible, but getting around it requires more complex queries. To get Cards
whose CardSet
user is the current user, you must embed a CardSet query within the Card query. The method that does this is whereKey:matchesQuery:
// this one finds CardSets whose user is currentUser
var innerQuery = PFQuery(className: "CardSet")
innerQuery.whereKey("user", equalTo:PFUser.currentUser())
// this one finds Cards whose CardSets match the preceding query
var query = PFQuery(className: "Card")
query.includeKey("cardset")
query.whereKey("cardset", matchesQuery:innerQuery);
query.findObjectsInBackgroundWithBlock //...
这篇关于ios swift parse:从3个类中收集数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!