Literal @YES not working in iOS 5 / Xcode 4.4

元气小坏坏 提交于 2019-11-29 10:02:00

The reason is Apple forgot the parentheses here:

#define YES             (BOOL)1

This will be fixed in iOS 6 SDK:

#define YES             ((BOOL)1)

In the meantime you must type @(YES).

James Webster

This is useful for information about literals.

A commenter on this answer also points out:

There is one small thing I'd like to warn about. Literal bools are also not supported because of this. However, a quick fix that I implemented was adding this to the beginning of one of my common headers (in an iOS project)

#ifndef __IPHONE_6_0 
#if __has_feature(objc_bool) 
#undef YES 
#undef NO 
#define YES __objc_yes 
#define NO __objc_no 
#endif 
#endif

@phix23s answer seems to be more to the point. You should accept that.

This was worth adding from comments:

It should be noted that this needs to be done after the #import . If one puts these #defines in their Prefix.pch, they should make sure to import Foundation earlier in the pch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!