我'我试图用基于Ribbit tuto的swift制作一个instagram克隆。人们可以分享照片并关注其他用户等。我使用Parse在用户之间进行了PFRelation
。我现在要做的是,在我的WalltableViewController
中显示,只有关注的用户发布。
我创建了一个函数来加载名为NSMutable
的{{1}}数组中的所有帖子。
我甚至做了一个函数来让被调用的timeLineData
NSMutableArray
跟踪用户...
但我没有成功使用followedFriends
过滤加载帖子功能。我有这个错误:followedFriends
,原因:Terminating app due to uncaught exception 'NSInvalidArgumentException'
这是我的代码:
'Cannot do a comparison query for type: __NSArrayM'
答案 0 :(得分:0)
FollowedFriends是一个数组,因此您需要使用containedIn
。如果您要与一个单独的对象进行比较,则使用equalTo
。把它改成这个。
findPost.whereKey("from", containedIn:followedFriends)
答案 1 :(得分:0)
我也创立了这个解决方案:
//query for the friends of the user
var friendsRelation: AnyObject! = PFUser.currentUser().objectForKey("KfriendsRelation")
var findFriends : PFQuery = friendsRelation.query()
//using the friends from the query above, we find all the posts of the friends of the current user
var findPosts:PFQuery = PFQuery(className: "UserPost")
findPosts.whereKey("from", matchesQuery:findFriends)
findPost.orderByDescending("createdAt")
//run the query
findPosts.findObjectsInBackgroundWithBlock { (objects:[AnyObject]!, error:NSError!) -> Void in
if !(error != nil) {
//found posts
self.tableView.reloadData()
} else {
// Log details of the failure
println("error loadind posts ")
}
}