How to create constant NSString by concatenating strings in Obj-C ?

Posted by eric-morand on Stack Overflow See other posts from Stack Overflow or by eric-morand
Published on 2010-06-17T08:44:02Z Indexed on 2010/06/17 8:53 UTC
Read the original article Hit count: 325

Filed under:

Hi guys,

I'm trying to instanciate a constant NSString by concatanating other NSString instances.

Here is what I'm doing in my implementation file :

static NSString *const MY_CONST = @"TEST";
static NSString *const MY_CONCATENATE_CONST = [NSString stringWithFormat:@"STRING %@", MY_CONST];

It leads to the following compilation error : Initializer element is not constant

I suppose this is because stringWithFormat doesn't return a constant NSString, but since there is no other way to concatenate strings in Obj-C, what am I supposed to do ?

Thanks for your help,

Eric.

© Stack Overflow or respective owner

Related posts about objective-c