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
ivan hernandez
Courses Plus Student 2,298 PointsProblem with USERS at PARSE (Luis <> luis)
I hope someone can help me with this NEW users in PARSE, I have a sign up and the problem is that for PARSE if I sign up like "Luis" is different from "luis" and it make 2 different users. how can I fix this??
Ben Jakuben any ideas??
2 Answers
Derek Medlin
6,151 PointsYou could just store the string as lowercase
NSString *username = textField.text.lowercaseString; // or wherever you're storing the user from.
And then when you retrieve the username just use the capitalizedString property. Just note that no matter what the user stores the username as, it will always come out starting with a capital letter followed by lowercase
username.capitalizedString; // 'derek' would now be 'Derek'
To do more of what i think you want to do, you could do this..
NSString *username = @"DEREK";
NSArray *listOfUsers = @[@"dErEk",
@"mEDLIN"];
// even though the strings have crazy capitalization, it will still show that the user exists
BOOL userExists = NO;
for (NSString *user in listOfUsers) {
if ([user compare:username options:NSCaseInsensitiveSearch] == NSOrderedSame) { // This basically looks at all the characters in the string as the same capitalization or ignores it
userExists = YES;
break;
}
}
if (!userExists) {
// TODO: Add code to add user to parse
NSLog(@"user does NOT exist!");
}
else {
// TODO: Alert the user that the username has already been taken
NSLog(@"user exists!");
}
On a side note, if you just wanted to compare two strings you could use
NSString *aString = @"teXt";
NSString *anotherString = @"TeXT";
if ([aString.lowercaseString isEqualToString:anotherString.lowercaseString]) {
// This condition will be true because it returns the strings as lowercase before comparing
}
ivan hernandez
Courses Plus Student 2,298 Pointsthank you for your answer, I will try this ...
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherGreat answer! Thanks for sharing!