First, private
Private-decorated properties, methods, and member variables can only be used in this class (fully private)
Fileprivate modified can be used in extension
Second, take the type
To take the type of a class, the class in OC is [Class class],swift. Self
1 // Uitabbarbutton Private class of the system, cannot be used directly 2 // if Value.iskind (of:UITabBarButton.self) {3if value.iskind (of:nsclassfromstring (" Uitabbarbutton")!) {
In extension, you can declare a computed property, but you cannot declare a stored property, as in OC
1 //expansion of the UIView2 extension uiview{3 4 //Extending calculated Properties5 var x:cgfloat{6 Get{7 returnframe.origin.x8}Set{9Frame.origin.x =NewValueTen } One } A}
Four, button add click event, OC with @,swift #
for:. Touchupinside)
Five, Agent
1 //1, the theorem proxy agreement, to inherit the Nsobjectprotocol, otherwise cannot use the weak reference2 protocol Wbtabbardelegate:nsobjectprotocol {3 func Didselectedcomposebutton ()4 }5 6 //2. Declaring proxy objects7 //with the weak keyword, the protocol must inherit Nsobjectprotocol8Weak var wbdelegate:wbtabbardelegate?9 Ten //3, the implementation of the agent method One //MARK:-click events A func composebuttonaction () { - //Execute Closures -Composebuttonclosure?() the - //invoking proxy methods using proxy objects - //? Indicates whether the preceding object is nil, and if it is nil then the code behind will not execute -Wbdelegate?. Didselectedcomposebutton () + } - + //4. Set Proxy objects ALet Wbtabbar =Wbtabbar () at //Set proxy Object -Wbtabbar.wbdelegate = Self - - //5, the implementation of the proxy method in the classification (swift, if the agent is declared and not to implement proxy method, will be an error) - //proxy methods can be implemented using extension - extension wbmainvc:wbtabbardelegate{ in func Didselectedcomposebutton () { -Print"I'm calling from a proxy object .") to } +}
Swift Usage note