Swift Usage note

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.