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

前端 未结 3 786
野的像风
野的像风 2020-12-18 20:10

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

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

static          


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 20:33

    I think you need to step back and think about if the string needs to be defined as a const.

    Clearly the string isn't a constant since you are trying to assign a new value to it - and that is not possible since you specifically instructed the compiler to make sure the value wasn't changed by using the const keyword.

    If the string resides as a property in a class you could make it a read-only property - i.e. accessor method but no setter method. You would then be able to construct your string as you wish in the class internally while keeping the callers from changing the value.

提交回复
热议问题