Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog
The properties in Swift are divided into storage properties and computed properties, which are data members in OBJECTIVE-C, calculated properties do not store data, but can be returned by calculating other properties.
Storage properties can store data in a constant attribute (defined by a keyword let) and variable attributes (defined by the keyword Var).
Storage Attribute Concepts:
We used the previous attribute, employee class, and department struct. Their class diagrams are as follows, and the Employee's Departmental attribute dept is associated with department.
We can specify default values when defining storage properties, as shown in the example code:
classEmployee {Let no:int=0 varName:string ="" varJob:string?varSalary:double =0 varDept:department?} structDepartment {Let no:int=0 varName:string =""} let EMP=Employee () emp.no= - //Compile Error: Modify constant property, program will compile errorLet dept=Department () dept.name="SALES" //Compile Error: Dept is a value type and value type cannot be modified, even if its property name is a variable property and cannot be modifiedLet emp1=Employee () emp1.name="Tony"
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 Products iOS, Cocos, mobile design courses please pay attention to the official website of Chi Jie Classroom: http://www.zhijieketang.com
Luxgen Classroom Forum Website: http://51work6.com/forum.php
Swift 2.0 Study Notes (day 31)--store properties