problem with rangeOfString debugger warning
problem with rangeOfString debugger warning
- Subject: problem with rangeOfString debugger warning
- From: 2551 <email@hidden>
- Date: Thu, 30 Jul 2015 15:11:01 +0700
I commonly use code like this to test if a string contains a substring
NSString *someString = @“This thing has an item.price and a discount.price”;
NSRange range = [someString rangeOfString “cost”];
if (range.location !=NSNotFound)
{
//do something
} else
{
//don’t do it
}
In one case where the string isn’t found, I’m getting a warning (Xcode 6.4, OS X 10.10.4) stating that
*** -[__NSCFString substringWithRange:]: Range {9223372036854775808, 9223372036854775830} out of bounds; string length 48. This will become an exception for apps linked after 10.10 and iOS 8. Warning shown once per app execution.
When I look in the debugger, I see that ‘rangeOfString’ has not returned {NSNotFound, 0} as promised in the docs, but huge numbers for location and length:
range NSRange location=4295047576, length=140734799794576
leading to the ‘out of bounds warning.
In the docs under ‘Special Considerations’ it says "This method detects all invalid ranges (including those with negative lengths). For applications linked against OS X v10.6 and later, this error causes an exception; for applications linked against earlier releases, this error causes a warning, which is displayed just once per application execution.”
My questions are: what causes this to be an “invalid range” rather than an NSNotFound? And: How do I avoid it when searching for a potentially non-existent string?
Any guidance much appreciated.
Best
Phil
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden