Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog
The syntax for classes and struct-body definitions in Swift 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 Name {
Defining members of a class
}
struct struct body name {
Define the members of the struct body
}
From the syntax format, the definition of classes and structs in Swift is more like Java syntax, and there is no need to put the interface and implementation parts in different files like C + + and objective-c.
Let's look at an example:
classEmployee {//the class defined varNo:int =0 varName:string ="" varJob:string?varSalary:double =0 varDept:department? }structDepartment {//defined structure Body varNo:int =0 varName:string ="" }
Some attributes are defined inside.
Employee and Department are related to the relationship.
The following statements are instantiated:
Let emp = Employee ()var dept = Department ()
Employee () and department () are instantiated by the constructor that invokes them.
Note: Is the class declared as a let constant or a var variable? 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
?
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 Learning Notes (Day 25)-class and struct definition