iOS Development Swift Chapter (01) Variables & Constants & Tuples

Source: Internet
Author: User

iOS Development Swift Chapter (01) Variables & Constants & Tuples

Description

1) Finally, write a swift. In fact, as early as 14 has been written in the swift part of the blog, but the passage of time, it is already different past. In addition, no corrections and updates are made to the blog post on the 14 part of the iOS development Swift feature.

2) The corresponding code for this blog post can be obtained in Https://github.com/HanGangAndHanMeimei/Code.

First, variables and constants

01 definitions of variables and constants

In swift, variables are decorated with Var, constants are decorated with let, variables can be modified and constants cannot be modified.

Variable: var

Constants: Let

Format: modifier (var|let) variable | constant name: data type = value

Note: In the use of swift development process, let is used in general, only when the data needs to be modified and then modified to Var, can guarantee data security.

  

02 Type Deduction

In Swift, if the variable | constant is initialized when it is defined, then the data type can be omitted and the data type of the variable | constant will be deduced automatically.

Recommendation: You should use automatic deduction whenever possible in development (unless you need to explicitly specify the length of the data or need to define a post-initialization), you can minimize the redundancy of the code.

   

03 Type Conversions

There are display conversions and implicit type conversions in OC, but there is no implicit type conversion in swift, only data of the same type can be assigned or evaluated.

Two, the meta-group

  A tuple is a composite data type that is referred to as a tuple whenever multiple data (which can be of the same or different data types) is used overnight ().

The advantage of tuples is that it is convenient to implement functions that return multiple values.

Tuple definition Format: constant | variable modifier constant | Name of variable: (data type 1, data type 2, data type 3) = (value 1, value 2, value 3)

  

iOS Development Swift Chapter (01) Variables & Constants & Tuples

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.