5

When building I was not getting any warnings but when archiving I got a lot of typing warnings all involving stringWithFormat and one an issue using NSNotFound. I was able to resolve all the stringWithFormat problems except for one, and still remain stumped by the NSNotFound issue. These are listed below. Thanks for any help

The following code...

    if ([[NSString stringWithFormat:@"%.*s", [data length], [data bytes]] isEqualToString:@"Success"]) {
        return YES;
    } 

Generates this warning for the format string...

Field precision should have type 'int', but argument has type 'NSUInteger' (aka 'unsigned long')

The following code...

    if (![_response rangeOfString:@"|TreatmentCards|0|"].location == NSNotFound) {
         return NO;

    }

Generates...

Comparison of constant 'NSNotFound' (9223372036854775807) with expression of type 'int' is always false

user278859
  • 10,379
  • 12
  • 51
  • 74

1 Answers1

0

I had this issue when grabbing an index of a mutable array. This link is helpful for understanding the issue. The root of the issue is that the data type being returned will never hit NSNotFound. Instead, set it like:

NSUInteger location = [_response rangeOfString:@"|TreatmentCards|0|"].location;

if (location != NSNotFound) {
    return NO;
}

There might be a cleaner way but this should work. It also can be used for the problem above if you declare the length to a variable of data type int.

Community
  • 1
  • 1