Why does @YES give an "expected expression" error, but @ compilation (YES)?

Using Xcode 4.4 Converting to a Modern C Object Syntax, my calls [NSNumber numberWithBool:YES]have been converted to @(YES). I had a problem that I just forgot about, and changed it myself to @YES, which should be the correct syntax.

However, this gives me an error:

Unexpected type name "BOOL": expected expression

I know that there is an expression syntax, but I don’t understand why I can’t just use @YESand @NO.

// Compiler error:
NSDictionary *userDefaultsDefaults = @{@"hasBeenLaunched": @YES};

// No error
NSDictionary *userDefaultsDefaults = @{@"hasBeenLaunched": @(YES)};

Why is there no @(YES)compiling while @YES, and what can I do to fix it?

+5
source share
2 answers

Short answer:

@(YES) @(NO)


:

, , Apple.

:

, . - . , , , ( iOS)

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

(, @YES) Clang XCode 4.5.

0

All Articles