static NSString usage vs. inline NSString constants

前端 未结 6 730
独厮守ぢ
独厮守ぢ 2021-01-30 09:03

In Objective-C, my understanding is that the directive @\"foo\" defines a constant NSString. If I use @\"foo\" in multiple places, the same immutable NSString object is referenc

6条回答
  •  忘了有多久
    2021-01-30 09:26

    It is not guaranteed that when using @"foo"in multiple places the runtime uses the same storage for them, and certainly may not be the case across compilation unit or library boundaries.
    I would rather use static NSString *string = @"foo", especially with a lot of literal strings.

提交回复
热议问题