Use objective-c method in swift seems crossing keyword of swift language

前端 未结 1 1158
滥情空心
滥情空心 2020-12-17 03:10

I have an objective-c method:

-(DeviceVar *)var:(NSString*)valid

In objective-c I simple use it as:

DeviceVar* rtc = [devic         


        
相关标签:
1条回答
  • 2020-12-17 03:44

    You can always enclose a reserved word in backticks if you need to use it as a method name (see for example Use reserved keyword a enum case):

    let rtc = device.`var`("etc")
    

    If you have write access to the Objective-C header files then another option is to define a different method name for Swift (compare Swift and Objective-C in the Same Project in the "Using Swift with Cocoa and Objective-C " reference):

    -(DeviceVar *)var:(NSString*)valid NS_SWIFT_NAME(deviceVar(_:));
    

    which can then be called from Swift as

    let rtc = device.deviceVar("etc")
    
    0 讨论(0)
提交回复
热议问题