Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

George S-T
George S-T
6,624 Points

Use of undeclared identifier 'isFriend' error when It's clearly defined.

In my EditFriendsViewController.h:

- (BOOL)isFriend:(PFUser *)user;

In my EditFriendsViewController.m:

- (BOOL)isFriend:(PFUser *)user {

}

Error is "Use of undeclared identifier 'isFriend'"

Doing the same thing that he does in the video, yet getting this error...

2 Answers

Stone Preston
Stone Preston
42,016 Points

you are defining a method inside of your didSelectRowAtIndexPath method. You cant do that. Move the definition out of that method and see if you still get that error. so you should have something like

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Makes the row not highlighted after clicking on it.
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    //The cell's accessory type is a checkmark.
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    //Friends relation = key friendsRelation.
    PFRelation *friendsRelation = [self.currentUser relationForKey:@"friendsRelation"];
    PFUser *user = [self.allUsers objectAtIndex:indexPath.row];

    //When a user is clicked on, add them as a friend.
    [friendsRelation addObject:user];

    //Save.
    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
    }];

}

- (BOOL)isFriend:(PFUser *)user {   //Error here!

}
George S-T
George S-T
6,624 Points

I want to punch myself. Thanks.

Stone Preston
Stone Preston
42,016 Points

are you calling that method anywhere? what line of code is giving you the use of undeclared identifier error?

George S-T
George S-T
6,624 Points
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Makes the row not highlighted after clicking on it.
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    //The cell's accessory type is a checkmark.
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    //Friends relation = key friendsRelation.
    PFRelation *friendsRelation = [self.currentUser relationForKey:@"friendsRelation"];
    PFUser *user = [self.allUsers objectAtIndex:indexPath.row];

    //When a user is clicked on, add them as a friend.
    [friendsRelation addObject:user];

    //Save.
    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
    }];

- (BOOL)isFriend:(PFUser *)user {   //Error here!

}