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