3

Recently I saw this code:

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
[configuration.preferences setValue:@TRUE forKey:@"xxxx"];

What does @TRUE stands for? I'm seeing this construct for the first time.

I know that YES equals to true and

@YES equals to NSNumber nubmerWithBool, but what does the @TRUE stands for?

StackOverflow question wtih example using "@TRUE" construct

Richard Topchii
  • 4,569
  • 3
  • 27
  • 70

2 Answers2

2

If you preprocess:

NSNumber *test = @TRUE;

it ends up being

NSNumber *test = @1;

(a clang literal for [NSNumber numberWithInt:1]).

which is logical, considering TRUE is preprocessed to 1.

This might be easier to see on:

#define MY_STRING "my_string"

NSString *string = @MY_STRING;

which gets preprocessed to:

NSString *string = @"my_string";
Sulthan
  • 118,286
  • 20
  • 194
  • 245
1

It's an NSNumber literal, a way of creating NSNumber instances from scalar literal expressions.

From The Clang 9 documentation:

In Objective-C, any character, numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object initialized with that value. Cā€™s type suffixes may be used to control the size of numeric literals.

Will Jones
  • 990
  • 5
  • 23