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