What is a better practice when defining a const NSString object in objective-c?

前端 未结 4 968
故里飘歌
故里飘歌 2021-02-09 21:21

When i read colleagues\' code in my team, i usually found there were two different types of definition for const NSString objects:

static NSString const *

4条回答
  •  长情又很酷
    2021-02-09 21:58

    NSString const *str
    

    means str is immutable.if you change str value for example str=str2, there's error occurs.

    NSString *const str
    

    means what str point to is immutable.You can change str = str2;

    since NSString is immutable

    NSString *const str 
    

    is equal to

    NSString *str
    

提交回复
热议问题