如何设置目标c中的第一个参数标签以用于swift



我想在swift中使用目标函数的第一个参数标签,可以通过在函数名中添加介词来完成。

- (void) makeRoundedWithCornerRadius: (CGFloat) cornerRadius;

我可以在像这样的swift项目中使用它(这是我所期望的(

myView.makeRounded(withCornerRadius: 16)

我做了另一个类似的功能

- (void) makeBorderWithColor: (UIColor*) color width: (CGFloat) width;

然而,当我准备在swift中使用它时,第一个参数标签并没有显示出我所期望的方式。我所期望的是

myView.makeBorder(withColor: .red, width: 10)

但它看起来像。。

myView.makeBorder(with: .red, width: 10)

它消除了颜色标签。我很困惑,甚至猜不出规则。

将Objective-C函数名转换为Swift的第一个参数标签的规则是什么?还有其他的方式来制作我想要的第一个论点标签吗?

您可以使用方法重命名–NS_SWIFT_NAME关键字:

- (void) makeRoundedWithCornerRadius: (CGFloat) cornerRadius width: (CGFloat) width NS_SWIFT_NAME(makeBorder(withColor:width:));

https://developer.apple.com/documentation/swift/objective-c_and_c_code_customization/renaming_objective-c_apis_for_swift

相关内容

最新更新