The swift programming language for IOS

Source: Internet
Author: User

Swift Language Fundamentals

Create a Workspace workspace, Project put workspace inside

Constants and variables for 1.Swift languages

① variable: var a=1,a=10 can also be modified after setting a variable var b=2

② constants are specified with Let, such as: let C =a+b

Once you assign a value to C, you can't adjust the value

The difference between a constant and a variable:

① variable can be arbitrarily changed after assignment

② constants usually cannot be changed after assignment, otherwise they will be error-

2.Swift Language data types

Indicate type: var s:string = "World" var i:int=1==

var words:string= "Southit"

In general, for the convenience of writing, not to specify the type, there is a fully automatic type of inference

3.Swift Language String Connection

var str= "Hello"

STR =str+ "Nanfangit"

printf (str)->result is: Hello Nanfangit

var i=200,var str = "Hello"

STR =str+ "World" str= "\ (str), asdef,\ (i)"//reference to a previously written variable

PrintIng (str)->result for Hello world,adef,200 string connection mode

4.swift language Arrays

① declares an array: var arr =["Hello,world", 100,2.3] can be written as any type

② declares an empty array: var arr=[],var arr2=string[] () means that there is an empty array that can only hold a specific type

5. Language Dictionaries

Dictionary equivalent to the map in C + +

such as: Var dictionary=["name:" "Sophia", "Age": "->result[name:sophia,age:18"

② dictionaries can also be dynamically assigned

dict["Sex"]= "Female"->[sex:female,name:sophia,age:18]

③ can take the characteristic position value by key

Printin (dict["name"])

The swift programming language for IOS

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.