Swift Grammar Chapter

Source: Internet
Author: User

The problem of assigning a variable value

1) constant let (it can be declared without assigning a value, but only once), variable var.

2) When the declaration is assigned, the compiler automatically calculates the type.

3) The display defines the variable type.

Let value:float = 4.0f

4) If you need to convert a value to a different type, use a cast.

Let AAA = 90;let bbb = ' Hello, world '; let CCC = BBB + String (AAA);

5) use \ () to convert the value to String

var a:int = 10;var B:int = 5;println ("sum = \ (A + B);");

6) array, dictionary generation  

Second, control flow

In a if statement, the condition must be a Boolean expression-which means that if score { ... } code like this will make an error without being cloaked in comparison with 0.

var array = ["A", "B", "C", "D", "E"];array[4] = "Apple";p rintln (array);        var dict = ["Key1": "Value1", "Key2": "value2"];d ict["Key3"] = "Value3";p rintln (dict);        Null dictionary and empty array var emptyarray = [string] (), var emptydict = [string, float] (), var emptydictarray = [[[String, Float]] ();

  

  

Swift Grammar Chapter

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.