Constants in Objective-C

后端 未结 14 1279
广开言路
广开言路 2020-11-21 22:10

I\'m developing a Cocoa application, and I\'m using constant NSStrings as ways to store key names for my preferences.

I understand this is a good idea b

14条回答
  •  被撕碎了的回忆
    2020-11-21 23:03

    If you want to call something like this NSString.newLine; from objective c, and you want it to be static constant, you can create something like this in swift:

    public extension NSString {
        @objc public static let newLine = "\n"
    }
    

    And you have nice readable constant definition, and available from within a type of your choice while stile bounded to context of type.

提交回复
热议问题