Fixing "direct string literal comparison has undefined behavior" automatically

In Xcode, I get the error "direct comparison of a string literal has undefined behavior" and I know why I get it, but is there any way for me to click the button and have Xcode clear this? I say this because in 370 places in my application I got this.

+8
objective-c xcode
source share
1 answer

The clang parameter to disable this warning is -Wno-objc-literal-compare .

However, warnings exist for some reason; this is because comparing with NSString literals using == does not guarantee that it will behave as you would expect. Instead, use isEqual: or isEqualToString: and you can both get rid of this warning and prevent this turn from turning into an error for you later.

+13
source share

All Articles