Learn notes from scratch (day 49)--Extended statement

Source: Internet
Author: User

??


original articles, welcome reprint. Reprint Please specify: Dongsheng's blog  

The syntax format for declaring an extension is as follows:

extensiontype name {   

    // add new features

}

the keyword that declares the extension isextension, the "type name" isSwift, including classes, structs, and enumerations, but we can still extend basic data types such as Integer, Float, Boolean, string, and so on, because these types are inherently struct-type. OpenIntis defined as follows:

struct Int:signedinteger {    init ()    init (_ Value:int)    static func convertfromintegerliteral (Value:int)-& Gt int    Typealias arrayboundtype = int    func getarrayboundvalue (), int    static var max:int {get}    static var min:int {get}}

visible from DefinitionIntis a struct type. is not onlyInttypes, the type of data that we are familiar with, such as Integer, Float, Boolean, string, and so on, is essentially struct-type.

Swift The new features in the extension mechanism that can be added in the original type include:

  • Instance calculation properties and type calculation properties

  • Instance methods and Type methods

  • Subscript

Content such as nested types can also be extended, and extensions can also comply with protocols.

Welcome to follow Dongsheng Sina Weibo@tony_Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
?
More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php

Learn notes from scratch (day 49)--Extended statement

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.