original articles, welcome reprint. Reprint Please specify: Dongsheng's blog
Swift The syntax for classes and struct-body definitions in is very similar. Classes use class keywords to define classes, and struct keywords are used to define structs, and their syntax is formatted as follows:
Class class Name {Defines a member of a class}struct struct name {Defines a member of the struct body}
from the syntax format, Swift The definitions in the classes and structs in are more similar to the Java Grammar, does not need to be like C + + and the objective-c in this way, the interface and implementation parts are placed in different files.
Let's look at an example:
Classes defined by class employee { // var no: Int = 0 var name: String = "" var job: String? var salary: Double = 0 var dept: Department? } struct department { // Defined structure Body var no: Int = 0 var name: String = "" }
Some attributes are defined inside.
Employee and the Department It's about the relationship. .
The following statements are instantiated:
Let emp = Employee () var dept = Department ()
Employee () and the Department () is to instantiate the constructor that calls them.
Note: The class is declared as Let constant is still var What about the variables? The class is generally declared as a Let constant from the programming process, because the class is a reference data type, and declaring that a let constant simply means that the reference cannot be modified, but the object that the reference points to can be modified.
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/M00/7C/AB/wKioL1bVaQPCD2hMAAAs2MBEZnc161.png "alt=" Wkiol1bvaqpcd2hmaaas2mbeznc161.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/1746423
Learn notes from scratch (Day 25)-Class and struct definitions