#defines in objective-c

How do #defines work in objective-c? I have experience in C / C ++, and now I'm trying to find objecive-c. #defines do not work in objective-c the way they work in c and C ++, where the compiler simply replaces all the definition links with what they should represent.

When I try to use #defines in objective-c, they only work occasionally. For example, when I do something like this:

#define NUMBER 5

int myArray[NUMBER];

I get compiler errors saying that there is no square bracket where, if I use this line, it works fine;

int myArray[5];

Surely they should be the same?

Also, if I try to use the #define value in any equations, I get similar compiler errors. This code does not work;

#define NUMBER 5

float var = NUMBER * 0.2;

where is it normal

float var = 5 * 0.2;

, , #defines - objective-c. XCode, , .

+3
3

#define Objective-C , C. , . , , , , - ?

+6

, #define.

+6

#defines, Xcode Build- > Preprocess, , .

+2

Source: https://habr.com/ru/post/1753568/


All Articles