How to declare a constant in swift that can be used in objective c

前端 未结 6 1520
刺人心
刺人心 2020-12-03 04:28

if I declare the swift constant as a global constant like:

let a = \"123\"

but the a cannot be found in

6条回答
  •  余生分开走
    2020-12-03 05:02

    Classes func don't work. The only solution I have found out is this one:

    class YourController: NSObject {
    
    @objc static let shared = YourController()
    
    private override init() { }
    
    @objc class func sharedInstance() -> YourController {
        return YourController.shared
    }
    
    @objc let terms = "Your-String-here"
    

    And then on Obj-c file:

    [[YourController sharedInstance].terms]
    

提交回复
热议问题