Difference between NSString literals

后端 未结 5 776
难免孤独
难免孤独 2020-11-27 06:46

What is the difference between these two lines?

NSString * string = @\"My String\";
NSString * string = [[[NSString alloc] initWithString:@\"MyString\"] auto         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 07:45

    One is a literal string, which persists for the life of the executing app. The other may be a dynamic object that only persists until autoreleased. (It may also be a literal string, if the system decides to optimize it that way -- there are no guarantees it won't.)

提交回复
热议问题