In Xcode, I'm getting the error "direct comparison of a string literal has undefined behavior," and I know why I'm getting it, but is there some way for me to click a button and have Xcode remove it? I'm saying this because in 370 places in my app I've gotten it.
The clang option to disable this warning is -Wno-objc-literal-compare
.
However, warnings are there for a reason; this one is because comparing against NSString literals using ==
is not guaranteed to behave as you might expect. Use isEqual:
or isEqualToString:
instead and you can both get rid of this warning and avoid having this turn into a bug for you later.
You can avoid the warning using `isEqualToString` instead of `==`.
`==` simply compares the pointers, which will usually be different even
if their contents are the same. The`isEqualToString` method compares
their contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With