我正在浏览这个链接.
但我真的没有得到以下两个代码片段之间的逻辑差异:
1.仅扩展符合协议ErrorPopoverRenderer的UIViewControllers.
protocol ErrorPopoverRenderer { func presentError(message: String, withArrow shouldShowArrow: Bool, backgroundColor: UIColor, withSize size: CGSize, canDismissByTappingAnywhere canDismiss: Bool) } extension UIViewController: ErrorPopoverRenderer { //Make all the UIViewControllers that conform to ErrorPopoverRenderer have a default implementation of presentError func presentError(message: String, withArrow shouldShowArrow: Bool, backgroundColor: UIColor, withSize size: CGSize, canDismissByTappingAnywhere canDismiss: Bool) {} }
2.仅为那些符合它的UIViewControllers扩展协议.
extension ErrorPopoverRenderer where Self: UIViewController { func presentError() { } }
无论哪种方式,任何符合协议的UIViewController子类都将具有默认方法实现,但在UIviewcontroller扩展或协议扩展中.什么是逻辑差异?如果我错了,请纠正我