Swift 2.0 Learning Notes (Day 25)-class and struct definition

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.