fastest in objC: IsEqualToString:@"" or length > 0?

Posted by Cœur on Stack Overflow See other posts from Stack Overflow or by Cœur
Published on 2012-08-30T08:33:22Z Indexed on 2012/08/30 9:38 UTC
Read the original article Hit count: 167

Filed under:
|

I'd like to know which one is fastest for testing a non-empty NSString for iOS 4.0+ (iPhone 3G). Note: the strings to test will be 99% of the time from 2 to 100 chars length.

if ([foo length] > 0)

or

if ([foo isEqualToString:@""] == NO && foo != nil)

I think it depends if isEqualToString: compares the length first (and in that case first way is faster) or if isEqualToString: compares first character of strings first (and in that case second way might be faster).

ps: I already know isEqualToString: is faster than isEqual: which is itself faster than compare:.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios