поэтому мое приложение хранит имя друга в ключе firstName
, фамилию в ключе lastName
и имя пользователя в классе parse, называемом friendsAssociation
, кроме того, он также сохраняет имя пользователя в имени пользователя в объекте, называемом пользователь. Я хотел бы запросить данные, чтобы найти все экземпляры, где пользовательский объект равен имени пользователя пользователя. Затем я хотел бы сохранить имя имени в массиве.Добавление данных в NSArray из запроса Parse
Вот копия кода я пытаюсь использовать
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]);
}
}];
конкретно я хотел бы использовать этот цикл для хранения данных в NSArray
называется Firstname
for (PFObject *object in objects) {
NSLog(@"%@", objects);}
firstname[objects.count]= [object objectforkey:@"firstName"];
}
Однако, Я не могу иметь строку [object objectforkey:@"firstName"]
, потому что объект не объявлен. Как я могу это исправить?