1. The same as before
2. Code
1 //2 //Viewcontroller.swift3 //Switflesson_exam4 //5 //Created by Sheyulon on 14-10-7.6 //Copyright (c) 2014 Dylan. All rights reserved.7 //8 9 Import UIKitTen One classViewcontroller:uiviewcontroller { A - Overridefunc viewdidload () { - super.viewdidload () the - //1. - //Change Temper - //initialization of 2 types of tuples +var a ="Alice" -var B ="Dylan" +var myType =(A, b) A at var name:string - var family:string -(name, family) = ("Alice","Dylan") - - //test func Change -Swap (&a, with: &b) in println (a) - println (b) to + //2. - //Print String the //test func flexstring *println (Flexstrings (S1:"Alice", S2:"Dylan")) $ Panax Notoginseng //3. - //Sumany the //test func Sumany +println (Sumany (1,2,3)) A the //4. + //Countfrom - //test func Countfrom $Countfrom (from:1, to:5) $ } - - /** the 1. Fun Change - Exchange values for 2 arbitrary objectsWuyi */ theFunc swap<t>(InOut a:t, inout with b:t) { -(A, b) =(b, a) Wu } - About /** $ 2. Func flexstrings - Output String - */ -Func flexstrings (s1:string ="", s2:string =""),String { A returnS1 + s2 = =""?"None": s1+S2 + } the - /** $ 3. Func Sumany the */ theFunc Sumany (Anys:any ...)String { the returnString ( the(Anys.map ({iteminch - SwitchItem { in Case "" asString,0 asInt: the return-Ten the CaseLet S asStringwhereS.toint () >0: About returnS.toint ()! the Case isInt: the returnItem asInt the default: + return 0 - } the}) as[Int]). Reduce0, combine: {Bayi$0+ $1 the }) the ) - } - the /** the 4. Func Countfrom the */ the func countfrom (#from: Int, to:int) { - println (from) the ifFrom <To { theCountfrom (From:from +1, to:to) the }94 } the the Overridefunc didreceivememorywarning () { the super.didreceivememorywarning ()98 //Dispose of any resources the can be recreated. About } - 101 102}
The Swift Foundation method in combat