Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

}