Structs and enumerations are similar to comparable studies: http://blog.csdn.net/lwjok2007/article/details/47975415
Structs are a custom type that is similar to enumerations but different from enumerations. Simply understand that a struct is a special class that has only attributes and no methods. A property in a struct is an object that has to be owned. For example, we define a student's body, including the school number, name, class. Then a student type of object will contain the school number, name, class all the information. If a variable is declared as an enumeration type, then he can only be one of the values in the enumeration.
1 Declaration/Declaration structure of struct body is generally used for the keyword struct. We look at an example, declaring a student struct struct Student {var studentid:int;//number var studentname:string;//name var studentclass: string;//class}//above declaration method we can see the data type that directly specifies each property. Another way is to not specify the data type, but directly assign value, the system automatically according to the assignment of data type struct Student1 { var studentid=2007001 var studentname= "" var The construction method of studentclass= ""}//2 structure//2.1 Null parameter construction method var zhangsan=student1 (); Because the struct must have an initial value, the null parameter construction method only applies to structs with default values. 2.2 Full parameter construction method var zhangsan1=student (studentid:2001, Studentname: "Zhang San", StudentClass: "Third grade")//3 structure of the value and assignment//structure of the value and assignment is very simple, Direct use. Syntax println (zhangsan1.studentname) zhangsan1.studentname= "John Doe" println (zhangsan1.studentname)//4 Finally we simply say that structs can be nested. For example, the student information may have a teacher's information, we can directly set the class teacher directly into a structure, then the student structure inside there will be a struct struct Teacher { var teachername= "Miss Wang" var teachersex= "female"}struct Student2 {var studentid:int;//No. var studentname:string;//name var studentclass: string;//class var teacherinfo:teacher;//head teacher Information}
Apple Development Group: 414319235 Welcome to join the Welcome discussion question
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift Structural Body