Swift Learning notes-2. Basic operators

Source: Internet
Author: User

Assignment operators

If the right side of the assignment is a multivariate group, its elements can immediately decompose multiple variables or variables let (x, y) = (1, 2)
x = 1, y = 2 The Swift assignment does not return any value, so the following code is wrong: if x = y {
This sentence error, because x = y does not regret any value
}"+" can also be used for concatenation of strings:"Hello" +"World"
Two character types or one character type and one string type, the addition generates a new string type: let Dog:character = "D"
Let Cow:character = "C"
Let Dogcow = dog + Cow Swift is 8% 2.5//equals 0.5 for floating-point number comparison OperationNote: Swift also provides two comparators, identity = = = And not identical, to determine whether two objects refer to the same object instance (!==). Empty merge operatorEmpty merge operator (a??). b) The optional type A is null-judged, if a contains a value to be unpacked, otherwise returns a default value B, which has two conditions:
    • Expression A must be of type optional
    • The type of the default value B must be consistent with the type of a stored value
The empty merge operator is a short expression of the following code:A! = nil? a!: bcode example: Let Defaultcolorname = "Red"
var userdefinedcolorname:string?
var colornametouse = userdefinedcolorname?? Defaultcolorname interval operator  The Closed interval operator (A...B) defines a range of values from A to B (including A and b), and b must be greater than a. For index in 1...5 {
println ("\ (index) * 5 = \ (Index * 5)")
The semi-open interval operator semi-open interval operator (a). <B) defines a range from A to B (not including B). Let names = ["Anna", "Alex", "Brian", "Jack"]
Let count = Names.count
For I in 0..<count {
println ("Person \ (i+1) is called \ (Names[i])")
}

Swift Learning notes-2. Basic operators

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.