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

前端 未结 6 1437
刺人心
刺人心 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 04:39

    In your swift class,

    let constant: Float = -1
    class YourClass: NSObject {
    class func getMyConstant() -> Float {return constant}
    ...
    }
    

    Clean, build to let xcode prepare this method useable for obj-c. Then at your obj-c class

    if ([YourClass getMyConstant] != 0) {
    ...
    }
    

提交回复
热议问题