Http://www.swiftv.cn/course/hw4sysi7 This course is short and adds up to one hours, suitable as a quick learn. 0. Environment Xcode-workspace-project-command Line OS X application 1. Variable type var variable let constant println () output requires no semicolon (c-like) and indentation (Python-like) but The branch manually indicates the type var x:int = 3 Note = Both sides should have a space (1) string connection str=str+ "\ (i) People" Here i is an integer variable (2) arrayvar x=["Hi", 1,0.2] empty array is [], empty string array is [string] () array can println (3) dictvar x=["HI": 2, "a": 3] Key and value by: Separate, pair is also separated by commas, note that the type of pair do not need to be the same x["s"]=f Same as assignment 2. loop control for I in 1 ... 100{}while i<arr.count{}for (Key,value) in dict{} if i%2==0{} optional variable var y:string? = "Tom" Y=nil If Let name=y{} 3. function
Func cal (A:int,b:int)-(int,int) { return(a+b,a-b)}let (m,n)=cal (3, 1 ) println (m)
var t=sayhi the function as the variable t ("Jack") 4. Class
1 Import Foundation2 3 classhi{4 5 func Sayhi () {6 7println"Hi, Jack .")8 9 }Ten One } A - varx=hi () - the X.sayhi () - - classhello:hi{ - + var_name:string - + Init (name:string) { A atSelf._name=name - - } - - Overridefunc Sayhi () { - inprintln"Hello \ (self._name)") - to } + - } the * varY=hello (Name:"Mike") $ Panax NotoginsengY.sayhi ()
Swift Basic Tutorials (Geek College) Notes