Swift 2.0 Learning Notes (Day 6)--what time do constants and variables use?

Source: Internet
Author: User

original articles, welcome reprint. Reprint Please specify: Dongsheng's blog

  use var or let

in the course of our development, when did you define the keyword as var , or is defined as Let it?

Actually AH all can satisfy our demand, then how should we choose?

For example, the PI can beπdefined as Letorvar.

letπ= 3.14159

varπ= 3.14159

The above code compiles without error. But from a business logic perspective,πshould be defined as a constant ( Let), because on the one hand constant ( Let) can not be modified, in addition to the use of constants in the program ( Let) can improve the readability of the program.

I think: In principle, first use Let , it has a lot of advantages, can prevent the program to run the process of unnecessary modification, improve the readability of the program. In particular, a let declaration is often used when referencing a data type declaration , although it is not a constant at the business level, but rather prevents the program from being incorrectly modified by its reference while it is running.


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 6)--what time do constants and variables use?

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.