Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
786 views
in Technique[技术] by (71.8m points)

objective c - Literal @YES not working in iOS 5 / Xcode 4.4

New Xcode 4.4 is out and it should support literals like

@42
@"String"
@23.0L
@{ @"key" : obj } and
@[obj1, obj2]

and it should also support @YES and @NO, which isn't working when targeting latest iOS 5 (and prior). After compiling it show the error message:

Unexpected type name 'BOOL': expected expression

I know you can fix it by typing @(YES) and @(NO). But I want to know the reason why it isn't working as expected.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...