1.和之前一样
2.代码
1//2//ViewController.swift3//SwitfLesson_exam4//5//Created by 薛雨仑 on 14-10-7.6//Copyright (c) 2014年 Dylan. All rights reserved.7//89import UIKit1011classViewController: UIViewController {1213overridefunc viewDidLoad() {14super.viewDidLoad()1516//1.17//Change Two temper18//2种元组的初始化19var a ="Alice"20var b ="Dylan"21var myType =(a, b)2223var name:String24var family:String25(name, family) = ("Alice","Dylan")2627//test func change28swap(&a, with: &b)29PRintln(a)30println(b)3132//2.33//print String34//test func flexString35println(flexStrings(s1:"Alice", s2:"Dylan"))3637//3.38//sumAny39//test func sumAny40println(sumAny(1,2,3))4142//4.43//countFrom44//test func countFrom45countFrom(from:1, to:5)46}4748/**491. fun change50交换2个任意对象的值51*/52func swap<T>(inout a:T, inout with b:T) {53(a, b) =(b, a)54}5556/**572. func flexStrings58输出字符串59*/60func flexStrings(s1:String ="", s2:String ="") ->String {61returns1 + s2 ==""?"none": s1+s262}6364/**653. func sumAny66*/67func sumAny(anys: Any...) ->String {68returnString(69(anys.map({itemin70switchitem {71case""asString,0asInt:72return-1073caselet sasStringwheres.toInt() >0:74returns.toInt()!75caseisInt:76returnitemasInt77default:78return079}80})as[Int]).reduce(0, combine: {81$0+ $182})83)84}8586/**874. func countFrom88*/89func countFrom(#from: Int, to:Int) {90println(from)91iffrom <to {92countFrom(from: from +1, to: to)93}94}9596overridefunc didReceiveMemoryWarning() {97super.didReceiveMemoryWarning()98//Dispose of any resources that can be recreated.99}100101102}