First, Swift basic operation
Import Frame
OC is #import <UIKit/UIKit.h> Swift is import UIKit
Swift definition Identifiers: Constants or variables must be specified
VAR (variable)/let (constant) identifier name: type of identifier = initialization value
var a: Int = ten; a = ; B = 3.11 wrong wording (type not correct)
let B: Double = 3.14;
3. The statement can not follow after the end;
Premise: A row has only one statement, if there are multiple statements in a row, you need to use; split
4. Print Content
Print (a)
Print ("Hello World")
Second, the use of constants and variables note points:
1. In the development of the first use of constants, only when the need to modify, when modified to Var
2. Constant essence: The saved memory address can not be modified, but can get the object through the memory address, and then modify the properties inside the object
Let View:uiview = UIView ()
view = UIView () error notation
View.backgroundcolor = Uicolor.redcolor ()
3. Create an Object
1. Create UIView object and make frame
Let view: UIView = UIView(frame: cgrect(x: 0, y: 0, Width: , Height:) )
2. Set properties of the UIView
View . BackgroundColor = uicolor. Bluecolor ()
//3. To add child controls inside a view object
3.1. Creating child controls
Enumeration used in //Swift : 1. type of enumeration . Specific type 2: Type of specific
let btn: UIButton = UIButton(type:. Contactadd)
3.2. setting The location of the BTN
btn. Center = cgpoint(x: y:-)
3.3. adds a child control to the in View
View . Addsubview(btn)
Third, the data type
// Type deduction
var a:int = 30
var a =
// You can view the type of an identifier by : Option + left mouse button
Let B = 3.14
01-swift Basic Syntax