为什么在Swift 3中没有重命名viewWithTag和其他方法? [英] Why isn't viewWithTag and some other methods renamed in Swift 3?
问题描述
在Swift 3中,许多方法都被重命名了.根据WWDC的会话之一,方法名称中的介词被移至参数名称:
In Swift 3, a lot of the methods got renamed. According to one of the sessions at WWDC, the prepositions in method names are moved to the parameter name:
UIView.animateWithDuration(1)
-> UIView.animate(withDuration: 1)
UIStoryboard.instantiateViewControllerWithIdentifier("some stuff")
-> UIStoryboard.instantiateViewController(withIdentifier: "some stuff")
所以我认为viewWithTag(1)
将重命名为view(withTag: 1)
,,但不是!
So I thought viewWithTag(1)
will be renamed to view(withTag: 1)
, but it isn't!
API准则中甚至提到:
There is even mentioned in the API guidelines:
尤其是当参数类型为NSObject,Any,AnyObject或基本类型(如Int或String)时,使用时的类型信息和上下文可能无法完全传达意图.在此示例中,声明可能很清楚,但使用地点不明确.
Especially when a parameter type is NSObject, Any, AnyObject, or a fundamental type such Int or String, type information and context at the point of use may not fully convey intent. In this example, the declaration may be clear, but the use site is vague.
func add(_ observer: NSObject, for keyPath: String)
grid.add(self, for: graphics) // vague
要恢复清晰性,请在每个弱类型参数前面加上一个描述其作用的名词:
To restore clarity, precede each weakly typed parameter with a noun describing its role:
func addObserver(_ observer: NSObject, forKeyPath path: String)
grid.addObserver(self, forKeyPath: graphics) // clear
我还发现SKNode.addChild
也没有重命名!
I also found that SKNode.addChild
is not renamed as well!
问题:
为什么这些方法没有重命名?他们忘了他们吗?还是API准则有例外情况?如果是,那是什么?
Why are these methods not renamed? They forgot about them? Or are there exception cases to the API guidelines? If yes, what are them?