Objective-C / C ++ constants

EDIT: My example may create some confusion. I modified the example below to reflect what I want to achieve. Hope this is more clear.

I am trying to define a constant in my objective-c code. I use the standard #define for this. For instance:

#define bluh "a"

I would like to define another constant like this

#define blah bluh +@"b"

The compiler throws an error (correctly) "Invalid operands to binary +". How can I make this work? Thanks for the help.

I also tried the objective-c method as follows:

NSString *const A =@"a";
NSString *const B = [NSString stringWithFormat:@"%@%@",A,@"b"];

But this gives me another error: “The initializer element is not permanent” Any help would be appreciated.

Greetings

+3
source share
2

C. ++ , :

#define blah bluh "b"

BTW/ , , , .

+2

c/++ , , . "string one-" "string two" "string one-string two" , .

, "@", , :

#define bluh "a"
#define blah bluh @"b"

Objective-C, , , .

+1

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


All Articles