Swift Study Notes

Source: Internet
Author: User

Constant: Let product_constant = "iphone6"

Variable: var product_var = "iPad" // you do not need to declare the variable type. The type of the left-side variable is derived based on the value on the right.

Multiple variables can be defined together: var X1 = 30, X2 = "ABC"

You can specify the variable type precisely: var X1: Int = 27 // specify X1 as the int type

Println (X1) // print a single variable

Println ("X1 = \ (X1), X2 = \ (X2)") // print multiple variables

 

Initialization string

VaR emptystring1 = ""

VaR emptystring2 = string ()

VaR string3 = "ABC"

VaR string4 = string ("ABC ")

Comparison string

If (string3 = string4 ){

}

Connection string

Let str1 = "hello"

Let str2 = "world"

VaR str3 = str1 + str2 // str3 is equal to "Hello World"

Str1 + = str2 // str1 is equal to "Hello World"

String case-sensitive Conversion

Let lowerstr = "ABC"

Let upperstr = lowerstr. uppercasestring // uppercase for lowercase

Let lowerstr2 = upperstr. lowercasestring // lower the upper case

 

Tuples constants and variables

Let product1 = (20, "iphone6", 5888)

Let product_name = "iphone4s"

VaR product2 = (10, "\ (product_name)", 3888)

Println (product1) // (20, iPhone 6, 5888)

Println (product2) // (10, iPhone 4 s, 3888)

 

 

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.