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

Implement a follow button in your app

How can you implement a follow button so user can follow ech other ? thanks

2 Answers

You should watch the self destructing message app videos to help you understand it better if you havent already

Ill explain it assuming you are using parse as your backend.

you would need an action for your button. Then inside that action would be the parse calls that actually implement the follower. Im assuming you have some properties defined and set already before to simplify this a bit

- (IBAction)follow:(id)sender {

     //Create the relation
     PFRelation *followingRelation = [self.currentUser relationForKey:@"isFollowing"];
     //Add the user that the currentUser wants to follow to the relation (assuming the user he wants to follow is stored    //in self.followed user
     [followingRelation addObject:self.followedUser];
     //save the current user
     [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if (!error) {

            //successful save

        } else {

            NSLog(@"%@ %@", error, error.userInfo);
        }
    }];

}

Thanks for help man @Stone Preston