【发布时间】:2015-03-03 05:44:29
【问题描述】:
所以我的应用程序在键 firstName 中存储了朋友的名字,在键 lastName 中存储了姓氏,在名为 friendsAssociation 的解析类中存储了用户名,此外它还将登录用户的用户名存储在名为 user 的对象中.我想查询数据以查找用户对象等于用户用户名的所有实例。然后我想将朋友的名字存储在一个数组中。
这是我尝试使用的代码的副本
PFQuery *query = [PFQuery queryWithClassName:@"friendsAssociation"];
//quesrys the class Friend asssociation to find when instances of "user" equal the
//logged in user's username
[query whereKey:@"user" equalTo:_user];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d users.", objects.count);
// Do something with the found objects
if (objects.count == 0) {
//uialert letting the user know that no phone number matches the query
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No User" message:@"No user matches this username"delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
//if there is an object matching the query
if (objects.count >=1) {
for (PFObject *object in objects) {
NSLog(@"%@", objects);}
firstname[objects.count]= [object objectforkey:@"firstName"];
}
//if there is more than one phonenumber matching the query as
//the user to input the friends username
//instead
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
具体来说,我想使用这个 for 循环将数据存储在名为 firstname 的 NSArray 中
for (PFObject *object in objects) {
NSLog(@"%@", objects);}
firstname[objects.count]= [object objectforkey:@"firstName"];
}
但是,我无法拥有[object objectforkey:@"firstName"] 行,因为未声明对象。我该如何解决这个问题?
【问题讨论】:
标签: ios objective-c arrays parse-platform nsstring