2015-03-03 42 views
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"]。我怎樣才能解決這個問題?

回答

0

您的for循環中出現語法問題(在使用object之前,用}關閉它)。

試試這個:

for (PFObject *object in objects) { 
    NSLog(@"%@", object); 
    [firstname addObject:[object objectforkey:@"firstName"]]; 
} 

編輯:通過這樣做,你可能要平衡去除與另外一個右花括號的留在你的代碼開放較早...