original articles, welcome reprint. Reprint Please specify: Dongsheng's blog
Swift the properties in are divided into storage properties and computed properties, and the stored properties are objective-c the calculated property does not store data in the data member, but you can return the data by evaluating other properties.
Store Properties data can be stored, divided into Constant Property (with the keyword Let definition) and Variable Properties (with the keyword var definition).
Storage Attribute Concepts:
We used the previous attribute, employee department structure. Their class diagrams are as follows, employee dept department
650) this.width=650; "Width=" "height=" 226 "title=" Untitled -1.jpg "style=" WIDTH:600PX;HEIGHT:226PX; "src= "Http://s4.51cto.com/wyfs02/M01/7C/AE/wKioL1bWSwKBI-HhAAecJSSdqZg862.jpg" border= "0" vspace= "0" hspace= "0" alt= " Wkiol1bwswkbi-hhaaecjssdqzg862.jpg "/>
We can specify default values when defining storage properties, as shown in the example code:
class employee { let no: int = 0 var name: string = "" var job: String? var salary: double = 0 var dept: department?} struct Department { let no: Int = 0 var name: String = ""} let emp = employee () emp.no = 100 //compile error : Modify constant properties, the program will compile error let dept = Department () dept.name = "SALES" // Compile Error: Dept is a value type, the value type cannot be modified, even if its property name is a variable property, you cannot modify let 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
650) this.width=650; "title=" 00.png "src=" http://s1.51cto.com/wyfs02/M02/7C/AE/wKioL1bWSyzBj9VoAAAs2MBEZnc318.png "alt=" Wkiol1bwsyzbj9voaaas2mbeznc318.png "/>
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
This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://tonyguan.blog.51cto.com/701759/1746594
Learning Swift from scratch (day 31)--Storing properties