Rather than a long if
statement, what is a more compact and readable way to verify if a string is contained in a collection of possible values? In other words, check if a value is within a domain?
I want to do something like this…
NSArray* domain = [NSArray arrayWithObjects:@"dog", @"cat", @"bird", nil];
BOOL valueFoundInDomain = [domain containsObject:@"elephant"];
But I'm concerned about equality checking with NSString. I want to check the value of the text, not object identity.
The documentation for NSArray says the containsObject
method uses the isEqual
method. But I cannot find in the documentation for NSString an explanation for its implementation of isEqual
. The presence of the isEqualToString
method suggests that isEqual
may be doing something else. If that something else involves interning of string objects, then experimenting myself may give misleading results, so I'd like a documented answer.