Swift 2.0 Study Notes (day 31)--store properties

Source: Internet
Author: User

Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog

The properties in Swift are divided into storage properties and computed properties, which are data members in OBJECTIVE-C, calculated properties do not store data, but can be returned by calculating other properties.

Storage properties can store data in a constant attribute (defined by a keyword let) and variable attributes (defined by the keyword Var).

Storage Attribute Concepts:

We used the previous attribute, employee class, and department struct. Their class diagrams are as follows, and the Employee's Departmental attribute dept is associated with department.

We can specify default values when defining storage properties, as shown in the example code:

classEmployee {Let no:int=0    varName:string =""    varJob:string?varSalary:double =0    varDept:department?} structDepartment {Let no:int=0    varName:string =""} let EMP=Employee () emp.no= -                    //Compile Error: Modify constant property, program will compile errorLet dept=Department () dept.name="SALES"           //Compile Error: Dept is a value type and value type cannot be modified, even if its property name is a variable property and cannot be modifiedLet 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
?
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 Study Notes (day 31)--store properties

Related Article

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.