Swift Notes 2

Source: Internet
Author: User

1. Tuple types

Let cat = (age:4,weight:2,cocle: "Black", beauty:true)

if (cat.beauty) {

printf ("I will not tell you my kitten has \ (cat.age) years old, weight \ (cat.weight) Jin");

}else{

printf ("Come and let me chop you Up");

}

2.optional Unpacking and binding

var tickit = "5000000"//Here is a value, if it is "Luoshuailuo" after the ToInt () there is no value , the Swift is expressed in nil

var money = Tickit.toint ()//string string converted to reshape ToInt ()

var = "money1:string!" //Indirect unpacking, more commonly used in initialization of classes         

If TickIT {

printf ("Congratulations to you, in the \ (Money!)   Yuan "); //But here will be who optinal (5000000), not the value we want, so use unpacking to add after money!

}

So how do bindings work? Binding allows us to do more in the subsequent code (said the same as not said, add it later)

If var temp = money {

var after tax = double (temp) * 0.5//temp for int type 0.5 is double, error required conversion, for large range Double conversion

printf ("Congratulations on your (temp) yuan, the amount of money you pay after tax")

}

3. Assert: Generally in the program debugging time use, set certain conditions must meet, otherwise the program immediately terminates.

var age = 17

ASSERT (Age > 18, "must be greater than 18 years old to play this game")

Swift NOTE 2

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.