Reputation: 1219
how can i check if a textfield contains a specific value i tried using the
if(x.text = @"hello")
however this would work since it would always show me the alertiview i had below this code. I think i am missing something from my comparision however i am unsure.
Upvotes: 1
Views: 478
Reputation: 92414
First of all, the code you've posted is an assignment (=), not a comparison (==). Then, what you need is ‘[x.text isEqual:@"hello"]‘. Otherwise you would be comparing pointers and they won't be equal.
Upvotes: 0
Reputation: 181460
You can use:
if ([x.text compare:@"hello"] == NSOrderedSame) {
// NSString are equal!
}
Hope it helps.
Upvotes: 3
Reputation: 170849
==
operator, not an assignment operator =
-isEqualToString:
method as == operator will check if pointers to objects are equal, not the string values they contain.So the correct code will be
if ([x.text isEqualToString:@"hello"])
Upvotes: 7