Reputation: 137
I have a string that I need to compare with an integer value.
I did this so far :
NSString *rad = [NSString stringWithFormat: @"%@", combo.selectedText];
srchParam.radius = rad;
if (srchparam.radius > 5)
{
//code here
}
What am I doing wrong ?
Upvotes: 1
Views: 2425
Reputation: 2491
Thats would be right!
if([[srchparam.radius] integerValue] > 5)
This example working in Xcode 4.5 with iOS SDK 6.0 if you still on Xcode 4.4 just change integerValue on intValue.
Upvotes: 0
Reputation: 31081
NSString *rad=[NSString stringWithFormat:@"%@",combo.selectedText];
if([rad intValue]>5)
{
//code here
}
Upvotes: 1
Reputation: 14113
I guess radius is an integer here. Thus :
NSString *rad=[NSString stringWithFormat:@"%@",combo.selectedText];
srchParam.radius =[rad intValue];
if((srchparam.radius)>5)
{
//code here
}
Upvotes: 1
Reputation:
Yes. Comparing an NSString using the <
operator will compare its memory address, not magically its contents (remember: Objective-C is not C++, there's no operator overloading). You have to compare the string's numerical value to the other integer using
if (([srchparam.radius intValue]) > 5)
{
// code here
}
Also, please use whitespaces - your code will be nicer and easier to read.
Upvotes: 1