When to use static string vs. #define

前端 未结 6 1815
-上瘾入骨i
-上瘾入骨i 2021-01-30 10:49

I am a little confused as to when it\'s best to use:

static NSString *AppQuitGracefullyKey = @\"AppQuitGracefully\";

instead of



        
6条回答
  •  花落未央
    2021-01-30 11:03

    After doing some search (this question/answer among other things) I think it is important to say that anytime when you are using string literal @"AppQuitGracefully" constant string is created, and no matter how many times you use it it will point to the same object.

    So I think (and I apologize me if I'm wrong) that this sentence in above answer is wrong: If you use a #define, there will be a separate copy of the string stored in the source on each use.

提交回复
热议问题