Notes on The Swift Programming Language-page 27th, swiftlanguage

Source: Internet
Author: User

Notes on The Swift Programming Language-page 27th, swiftlanguage

· Page 27th

 

1 type safelanguage

The main content on this page is that the swift language is a secure programming language for "type check", meaning that the Left value of the value assignment statement must be the same as the right value, if the left value is declared as a string variable, the right value of the equal sign should be a string caused by double quotation marks, rather than an integer or floating point data.

During code compilation, the compiler checks the left and right values of the value assignment statement. If the type does not match, the compiler reports an error, that is, it checks data security to ensure data consistency.

2 type inferencelanguage

Swift will check the consistency of data types during compilation, but it does not mean that the type of a variable or constant must be specified when defining constants and variables, because swift has a mechanism called type inference language.

The swift language compiler will automatically infer that the constant or variable should belong to that data type based on the initialization value assignment statement of the constant or variable.

Eg1: let s1 = "www. chinagame. me"

Based on the left value of the value assignment statement "www. chinagame. me", swift concludes that the type of the s1 constant is string.

In this way, swift developers do not need to define s1 constants as follows.

Let s1: String = "www. chinagame. me"

Under the type inference mechanism

Let s1 = "www. chinagame. me"

It is equivalent to the let s1: String = "www. chinagame. me" declaration that s1 is a constant.

Keywords: type check, type safe variable agge, type inference




For swift

Swift is good. In fact, it is better to learn the basics. If you learn it directly, you may not understand it in some places. I have some Chinese learning materials. Leave your email and I will give it to you.
 
Answers to assignments for summer vacation

I lost a black notebook and a red "hero" pen in the reading room on March 13, March 7. If someone finds it, please contact me. Thank you! On October 18, March 7, I picked up a notebook and a pen in the reading room. Please contact XXX of XX class for the error message.
 

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.