Swift summarizes a

Source: Internet
Author: User

1. Data type

The first letter of the type is capitalized
Integer
Int
Int8 Int16 Int32 Int64
UInt8 unsigned number:

Float
Double
String
Array
Dictionary

Type inference
var num = 1//default integer
var d = 1.23//default double

Swift character
Double quotes 1 characters
Let C:character = "a"
var a:character
A = "a"
A = "LV"



2. Overflow
32-bit Maximum value
Let Overvalue:uint32 = Uint32.max
Overflow error
Let Overvalue2:uint32 = uint32.max+1

3. There is no implicit conversion between different data types can not directly calculate the need for strong turn
var d:double = 2.1
var int2:int
Strong value double to int
Int2 = Int (d)

4. Boolean values
Swift introduces True Boolean true flase and C + + similar

The IF expression must be a Boolean or the value of an expression is a Boolean

5. Tuples
/*
Tuple ("Xiaohong") multiple identical data types or different data types together this is a tuple
*/
Tuples do not need to be defined directly using
Let student = ("Zhang San", 23, 98.6)
println (Student)
println (student.0,student.1,student.2)

You can also define templates like this
Let Stu:(string,int,double) = ("Xiaohuang", 2,1.1)

Another form of extracting the value of a tuple
Let STU1 = (name: "Zhangsan", age:23)
println (Stu1.name)
Tuples are often used together with functions as parameters and return values equivalent to returning multiple Values C language can only return one value

6. Selectable values
/*
Optional value Swift is unique
Optionals has a value or no value like a Boolean value

Both states have values that have no value nil
*/

A value of 9 contains an integer value
var p1:int? = 9
No value
var p2:int? = Nil
Or
var p3:int?

//! Forced resolution of optional values if it is nil cannot force parsing of optional values
Get optional values to add!

Swift summarizes a

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.