Objective c 我可以在NS\U SWIFT\U名称中使用保留关键字吗?
我试图使Objective-C委托协议更美观,以便在Swift中使用,但我在弄清楚如何使用Objective c 我可以在NS\U SWIFT\U名称中使用保留关键字吗?,objective-c,swift,Objective C,Swift,我试图使Objective-C委托协议更美观,以便在Swift中使用,但我在弄清楚如何使用NS\u Swift\u NAME时遇到了一些问题。是否可以使用NS\u SWIFT\u NAME在SWIFT名称中指定与Objective-C关键字同名的参数(特别是中的和) 这不会生成: @protocol MyContainerDelegate -(NSInteger)myContainerContentsCount:(MyContainer *)container NS_SWIFT_NA
NS\u Swift\u NAME
时遇到了一些问题。是否可以使用NS\u SWIFT\u NAME
在SWIFT名称中指定与Objective-C关键字同名的参数(特别是中的和)
这不会生成:
@protocol MyContainerDelegate
-(NSInteger)myContainerContentsCount:(MyContainer *)container
NS_SWIFT_NAME(contentsCount(in container:));
@end
但是如果我将它声明为NS\u SWIFT\u NAME(contentsCount(inContainer:)
它就可以工作了
我很确定我见过Swift方法,它们的外部参数名有for
或in
,但我不知道在哪里可以找到这样的示例定义。这可以通过NS\u SWIFT\u NAME
实现吗?问题不在于关键字,而是您指定了这两个参数
NS\u SWIFT\u name
中的标签和参数名称。参数标签
这就足够了。与
@protocol MyContainerDelegate
-(NSInteger)myContainerContentsCount:(MyContainer *)container
NS_SWIFT_NAME(contentsCount(in:));
@end
协议导出到Swift作为
public protocol MyContainerDelegate {
public func contentsCount(in container: MyContainer!) -> Int
}