我是使用parse的新手,目前正在向使用SOAP Web服务替换它们的应用程序添加解析。
现在我有点陷入困境,因为在MySQL和php中完成它我试图将表和代码中的逻辑转换为解析。
我有一个我写过的函数,它实现了我所追求的,但是我认为它错了,可以做得更好,对于初学者我不是在调用findObjectsInBackground,我知道我需要。
我正在尝试获取此结果,然后重新加载tableView。
NSMutableArray *activityfeed = [NSMutableArray new];
//get current user
PFUser *user = [PFUser currentUser];
if (user != nil) {
PFQuery *query = [PFQuery queryWithClassName:@"Event"];
//get event that user is involved in
[query whereKey:@"invited" equalTo:user];
//get the events
NSArray *events = [query findObjects];
//loop over the events
for (PFObject *event in events) {
//owner is a pointer to the users class
PFUser *owner = event[@"owner"];
if (![user.objectId isEqualToString:owner.objectId]) {
//ignore the info for the logged in user for now
//invited is a relation so one event has many users
PFRelation *relation = [event relationForKey:@"invited"];
PFQuery *query = [relation query];
[query orderByDescending:@"dateinvited"];
[query addDescendingOrder:@"dateaccepted"];
//get the friends that are involved with the event
NSArray *friends = [query findObjects];
for (PFUser *friend in friends) {//Perform logic checks here and then add to activityfeed}
}
}
}
return activityfeed;
因此,上面的逻辑获取当前用户,然后获取用户参与的所有事件,然后让所有其他人参与该事件,然后确定要显示的内容。
是否有更有效的方法来完成上述工作?