Leo*_*ica 5 swift objective-c-swift-bridge swift3
我有两个 C 函数:
extern UIColor* LNRandomDarkColor();
extern UIColor* LNRandomLightColor();
Run Code Online (Sandbox Code Playgroud)
作为练习,我尝试将它们作为UIColor.
以下为 WWDC 2016 中 Apple 的“Swift 新增功能”演示示例:
void CGContextFillPath(CGContextRef) NS_SWIFT_NAME(CGContext.fillPath(self:));
Run Code Online (Sandbox Code Playgroud)
我尝试类似地注释我的函数:
extern UIColor* LNRandomDarkColor() NS_SWIFT_NAME(UIColor.randomDarkColor());
extern UIColor* LNRandomLightColor() NS_SWIFT_NAME(UIColor.randomLightColor());
Run Code Online (Sandbox Code Playgroud)
但是我收到以下警告:
'swift_name' 属性只能应用于带有原型的函数声明
我在这里做错了什么?
更新:为此问题打开SR-2999 。
这是部分结果。根据 \n SE-0044 Import as member \xe2\x80\x93\n 处的示例创建的以下代码\n \xe2\x80\x93 进行编译:
\n\nstruct MyColor { };\n\nUIColor * _Nonnull LNRandomDarkColor(void)\n__attribute__((swift_name("MyColor.randomDarkColor()")));\nRun Code Online (Sandbox Code Playgroud)\n\n并将 C 函数作为MyColor\ntype 的静态成员函数导入到 Swift:
let col = MyColor.randomDarkColor()\nRun Code Online (Sandbox Code Playgroud)\n\n但我无法将该函数作为任何现有类型的成员函数导入,例如UIColor:
UIColor * _Nonnull LNRandomDarkColor(void)\n__attribute__((swift_name("UIColor.randomDarkColor()")));\n// warning: imported declaration \'LNRandomDarkColor\' could not be mapped to \'UIColor.randomDarkColor()\'\nRun Code Online (Sandbox Code Playgroud)\n\n(并且UIColor.randomDarkColor()不编译)。我不知道这是一个故意的限制还是一个错误。
使用NS_SWIFT_NAME宏而不是swift_name\nattribute 也不起作用:
UIColor * _Nonnull LNRandomDarkColor(void)\nNS_SWIFT_NAME("MyColor.randomDarkColor()");\n// warning: parameter of \'swift_name\' attribute must be a Swift function name string\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
3427 次 |
| 最近记录: |