如何设置目标c中的第一个参数标签以快速使用?

问题描述

我想迅速使用目标函数的第一个参数标签,可以通过在函数名上添加介词来实现。

- (void) makeRoundedWithCornerRadius: (CGFloat) cornerRadius;

我可以在这样的快速项目中使用它(这是我所期望的)

myView.makeRounded(withCornerRadius: 16)

我做了另一个这样的功能

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

但是,当我要快速使用它时,第一个参数标签并没有显示我期望的方式。 我期望的是

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