Constants in Objective-C

后端 未结 14 1195
广开言路
广开言路 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.

    0 讨论(0)
  • 2020-11-21 23:05
    // Prefs.h
    extern NSString * const RAHUL;
    
    // Prefs.m
    NSString * const RAHUL = @"rahul";
    
    0 讨论(0)
提交回复
热议问题