0
所以我的应用程序商店一个朋友在关键firstName
头名,在关键lastName
姓和名叫做此外friendsAssociation
它也存储在用户的用户名在调用的对象已签署用户。我想查询数据以查找用户对象等于用户用户名的所有实例。然后,我想将朋友的名字存储在数组中。从分析查询添加数据的NSArray在解析类
下面是代码的副本,我试图用
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 (PFObject *object in objects) {
NSLog(@"%@", objects);}
firstname[objects.count]= [object objectforkey:@"firstName"];
}
然而,一个NSArray
使用for循环来存储数据,由于未声明对象,因此我无法获得线路[object objectforkey:@"firstName"]
。我怎样才能解决这个问题?