Using a constant NSString as the key for NSUserDefaults

前端 未结 4 1135
借酒劲吻你
借酒劲吻你 2021-01-29 18:27

I\'m using NSUSerDefaults to store user preferences. I remember reading somewhere that setting the keys as constants is a good idea - and I agree. The following code is what I c

4条回答
  •  情书的邮戳
    2021-01-29 18:45

    For access from other classes:

    .h

    extern NSString * const PolygonNumberOfSidesPrefsKey;
    

    .m

    NSString * const PolygonNumberOfSidesPrefsKey = @"PolygonNumberOfSides"
    

    For access only inside current class:

    .m

    static NSString * const kPolygonNumberOfSidesPrefsKey = @"PolygonNumberOfSides"
    

提交回复
热议问题