What would be the best method to compare an NSString to a bunch of other strings case insensitive? If it is one of the strings then the method should return YES, otherwise NO.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Here's a little helper function:
Of course this could be greatly optimized for different use cases.
If, for example, you make a lot of checks against a constant bunchOfStrings you could use an
NSSet
to hold lower case versions of the strings and usecontainsObject:
:Just to add a few additions to Nikolai's answer:
NSOrderedSame
is defined as 0So if you call
caseInsensitiveCompare:
on anil
object you would getnil
. Then you comparenil
withNSOrderSame
(which is 0) you would get a match which of course is wrong.Also you will have to check if parameter passed to
caseInsensitiveCompare:
has to be not nil. From the documentation: