I am trying to detect whether a NSNumber is between 0 and 255 or not. Whenever I run the app, I receive the alert view that my number is greater than 255, even when it is not. I do not have this problem with 0.
if (redValue < 0) {
NSLog(@"Red value is less than 0");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your number must be greater than 0." message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else if (redValue > 255) {
NSLog(@"Red value is greater than 255");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your number must be less than 255." message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
Additionally, I receive this warning on the "else if (redValue > 255)" line: Ordered comparison between pointed and integer ('NSNumber *' and 'int'), So I'm assuming I have to convert this NSNumber to an integer?
Should be:
if([redValue intValue] < 0) {
...
if([redValue intValue] > 255) {
...
Assuming it is an int. If it isn't go to the NSNumber Class Reference look under "Accessing Numeric Values" and replace intValue
with the appropriate thing.
use intValue to get the number as an int:
[redValue intValue]
try this
[redValue intValue] > 255
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With