扩展协议如何使用的有关的UIViewController的UIViewController的财产

问题描述:

public protocol NavigationBarNormalStyle { 
    var titleView: UIToolbar! {get} 
    var rightButton: UIButton? {get} 
} 

public extension NavigationBarNormalStyle where Self == UIViewController { 

    var titleView:UIToolbar { 
     var titleViewBar = UIToolbar(frame: CGRect(x: 0.0, y: 0.0, width:Self.view.width, height: 44)) 
     titleViewBar.barTintColor = UIColor.whiteColor() 
     Self.view.addSubview(titleViewBar) 
    } 

} 

Self.view.width是错误的...如何使用VC的财产?扩展协议如何使用的有关的UIViewController的UIViewController的财产

要访问实例属性,但Self是对象的,而不是对象本身。

你应该写self.view