Xcode使用默认参数值显示功能/方法的提示时,是否有任何规则?
这就是我的意思。例如,在具有如下签名UIViewController
的present()
方法中:
func present(
_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil
)
当我在Xcode中键入其名称时,仅提示完整的方法声明,包括completion
参数,可以省略:
存在(viewControllerToPresent:UIViewController,动画:Bool,完成:(()-> Void)?)
但是,让我们创建present
方法的副本:
func presentCopy(
_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil
) {...}
这次,Xcode通知了该方法的两个可能版本:
presentCopy(viewControllerToPresent:UIViewController,动画:Bool)
presentCopy(viewControllerToPresent:UIViewController,动画:Bool,完成:(()-> Void)?)
这种不一致来自何处?
我猜这是因为您是在纯Swift类中定义方法,而present
of的方法UIViewController
是在Objective-C类中定义的。
在Objective-C中,没有默认参数值的概念。
甚至相反。如果presentCopy
在Obj-C类内部访问方法,则方法声明将具有所有值,并且将只有一个方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句