如何在 objective c 中设置第一个参数标签以在 swift 中使用?
How to set first argument label in objective c to use in swift?
我想在swift中使用objective函数的第一个参数标签,可以通过在函数名中添加介词来实现。
- (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:));
我想在swift中使用objective函数的第一个参数标签,可以通过在函数名中添加介词来实现。
- (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:));