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

Parse: Detect User

So I'm working on a Parse project. I want to be able to detect the username and if it is a certain username (for instance, if the username is me, gregg, then is would do something). I have the general gist of how to do this down, by using a conditional and the == operator. I'd really appreciate if anyone could show me how to do this.

2 Answers

patrick tagliaferro
patrick tagliaferro
5,399 Points

I am new to this but couldn't you do something like

PFUser *currentUser = [PFUser currentUser];
NSString *userName = currentUser.username;

if ([username isEqual:@"greg"]){
  //do something
}

Thanks!

Stone Preston
Stone Preston
42,016 Points

since username is a string you will most likely need to use the isEqualToString method. try something like:

if ([[[PFUser currentUser] username] isEqualToString:@"gregg"]) {

}