Static properties of Swift

Source: Internet
Author: User

Object Type Instance Store property static Storage Property Instance calculation property static Computed property

Support support is not supported for class support

     Structure                        Support                           Support                       Support                            Support

Enumeration does not support support support support



Instance Store properties static Storage Property Instance calculation property static Computed property

Instance calculation properties can be used to

Static computed properties may not be able to


1. The instance calculation attribute can access all the attributes;

2, static computed properties can only access static properties, cannot access instance properties;


Static properties of a struct

There is such a class design, there is an account class, assuming it has 3 properties: Amount (account amount), interestrate (interest rate) and owner (account name), in this class, amount and owner will vary, different people the content of these accounts is different, The interestrate of all accounts are the same.


The attributes of the amount and owner are related to the account individual, become instance attributes, the InterestRate attribute is independent of the individual, or is shared by all account individuals, which is called a static attribute or type attribute


3 Object-oriented types (structs, enumerations, and classes) can all be defined as static properties, with their syntax in the following format:


struct struct body name {

static VAR (let) store property = ""

Static Var evaluates the property value {

get{

Return

}

Set ()

}


}


Ii. enumeration of static properties


Enum enum Name {

static VAR (let) store property = ""

Static Var computed property: Data type {

get{

Computed property values

}

Set (new property value) {


}

}


}




Third, class static properties


Class Name {

Class Var computed property Name: property data type {

get{

Return computed property value

}

Set (new property value) {


}

}


}


This article is from the "Ordinary Road" blog, please be sure to keep this source http://linjohn.blog.51cto.com/1026193/1622195

Static properties of Swift

Related Article

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.