Swift First Knowledge

Source: Internet
Author: User
Tags number sign

OneGrammatical features: reference to OC, C #, JavaScript, Rython and other language featuresIt also has the high performance of the compiled language and the flexibility of the scripting language . The code is simple,can be easily mixed with OC, C (call each other)Development conditions: Xcode >= 6.0, OS X > 10.9.3Ii. Grammar: Source file extension:. Swift 1, do not need to write the main function: from the top down in order to execute, the first code automatically as the program's entry 2, do not need to add a semicolon after each statement:You can also add semicolonsThere is a case where you must add a semicolon: when there are multiple statements on the same line of codeComments:Multi-line comments can be nested annotationsdeclaring constants with let radius = 1.2declare the variable with var: var x = 1.1,,y = 2.1,z = 3.2Swift Program:

var btn = UIButton ()

Btn.frame = CGRectMake (20, 20, 100, 80)

Btn.backgroundcolor = Uicolor.bluecolor ()

Self.view.addSubview (BTN)

var ImageView = Uiimageview (Image:uiimage (named: "2x"))

Imageview.frame = CGRectMake (20, 100, 100, 100)

Self.view.addSubview (ImageView)

Use of playground:

Import UIKit

var str = "Hello, playground"

var num = 12

num++

num + = 11 + 12 * 3

var btn = UIButton ()

Btn.frame = CGRectMake (0, 0, 100, 100)

Btn.backgroundcolor = Uicolor.redcolor ()

Btn.layer.cornerRadius = 10

Btn

Test, row by line displaysimple manipulation of strings:

var str = "A b C"

var str2 = "D E F"

var string = str + str2//stitching string

var age = 18; var num = 1024

var name = "Lily"

var lily = name + "is \ [age] years old, and no" + String (num)

Print (Lily)

Named:you can basically name any character that you like as a constant or variable.on Mac by using control+command+ space: Eject emoji keyboard =??、???? Cannot contain:number sign (+-*/), arrow (), illegal invalid Unicode character (??). ), keyword, number start, individual underline 、、、

Swift First Knowledge

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.