I use this code to compare two strings:
NSComparisonResult result = [cellTitle compare:searchText options:(NSCaseInsensitiveSearch && NSLiteralSearch)];
but xcode shows warning about using logical && and offers to use bitwise &, by bitwise & the comparison don't return correct result.
How can I fix it?
You're trying to combine two parts of a bitmask. You can use the bitwise OR or XOR operators, or an addition for this - |
, ^
or +
. The norm would be |
.
You should be doing:
NSComparisonResult result = [cellTitle compare:searchText
options:(NSCaseInsensitiveSearch | NSLiteralSearch)];
Those flags are a binary numbers with only one 1 set. So when you do a logical |, you get the "mix" of both (Ex: 1000 | 0100 => 1100), that way you can set several flags as options.