史上第二强大的swift入门

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

func test(number1: Int, number2: Int, isok: ((Int,Int) -> String)[]) -> String {
    var result:String? = ""
    let count = isok.count
    for i in 0..count {
        result = isok[i](number1, number2)
        println("result:\(result)")
    }
    return result!
}

//比较大小
func compare (number1:Int, number2:Int) -> String {
    var result: String? = ""
    if number1 > number2 {
        result = "\(number1) 比\(number2)大"
    } else if number1 < number2 {
        result = "\(number1) 比\(number2)小"
    } else {
        result = "\(number1) 等于\(number2)"
    }
    return result!
}

//做加法
func plus(number1:Int, number2:Int) -> String{
    var result:String?
    result = "\(number1) + \(number2) =\(number1+number2)"
    return result!
}


var result:String?
var isok: ((Int,Int) -> String)[] = [compare,plus];

result = test(9,4,isok)