为什么
-(void)addSimpleListener:(id<XXSimpleListener>)listener
转换为快速外观,如下所示:
func add(_ listener: XXSimpleListener?) {
}
但是将方法更改为此
-(void)addSimpleListener:(id<XXSimpleListening>)listener
它将转换为
func addSimpleListener(_ listener: XXSimpleListening?){
}
Xcode (or whatever tool you are using to do the conversion) is merely following Swift API guidelines. Specifically:
In the first case, the words
SimpleListener
inaddSimpleListener
is repeating the type of the parameter, so they are removed from the method name. However, in the second case,SimpleListener
andSimpleListening
does not look the same to whatever tool you are using, so it thinks thatSimpleListener
should be kept.In my (human) opinion though, I think the method should be named
addListener
, because:Listener
is the role of the parameter.