Class expansion extension in Swift

Source: Internet
Author: User

To add a color, for example, the new Swift folder is not a cocoa class and does not need to inherit anything.

And then

1 Import UIKit2 3 Protocol colordalegate{4     classFunc Maincolor (Void)Uicolor5 }6 7 extension uicolor:colordalegate{8     classFunc Maincolor (Void)uicolor{9        returnUicolor.redcolor ()Ten     } One}

This defines a colordalegate protocol, which is then implemented by Uicolor to implement the method declared in this protocol, and here's why it's written, and that's why you add that class,

If the Redcolo () of the system is called by Uicolor.redcolor () to see Redcolor's declaration to this interface, here is a partial intercept

1  classFunc blackcolor ()-Uicolor//0.0 White2     classFunc Darkgraycolor ()-Uicolor//0.333 White3     classFunc Lightgraycolor ()-Uicolor//0.667 White4     classFunc Whitecolor ()-Uicolor//1.0 White5     classFunc Graycolor ()-Uicolor//0.5 White6     classFunc Redcolor ()-Uicolor//1.0, 0.0, 0.0 RGB7     classFunc Greencolor ()-Uicolor//0.0, 1.0, 0.0 RGB8     classFunc Bluecolor ()-Uicolor//0.0, 0.0, 1.0 RGB9     classFunc Cyancolor ()-Uicolor//0.0, 1.0, 1.0 RGBTen     classFunc Yellowcolor ()-Uicolor//1.0, 1.0, 0.0 RGB One     classFunc Magentacolor ()-Uicolor//1.0, 0.0, 1.0 RGB

There is a class for each of them, although I do not know why, but like this kind of thing only need to imitate the system to write, it is absolutely correct.

Class extension extension in Swift

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.