Swift-7-閉パッケージ

5238 ワード

// Playground - noun: a place where people can play



import UIKit



// swift     C OC  blocks    

// 1.                 2.           return    3.        4. Trailing    

//       in                 ,     

/**

    {(parmeters) -> return type in 

        statements

    }

*/



var names = ["Anna", "Alex", "Ewa", "Barry", "Daniella"]

sorted(names, { (s1 : String, s2 : String) -> Bool in

    return s1 > s2 //           return       return    

})



//         

//               ,              (String, String) -> Bool ,swift                   ,               

sorted(names, { s1, s2 in

    return s1 > s2

})



//          $ +             0      

sorted(names, {return $0 > $1}) //        return    ,  Xcode              {$0 as String > $1 as String}     $0 $1 String  



// swift     string  >      2 String     ,    Bool ,       ,      

sorted(names, >)



// Trailing Cloures     :                             

func someFunctionTakesCloures(cloures : () -> ()) {

    println("do some thing")

}



//    trailing cloures  

someFunctionTakesCloures({

    //       

})



//   trailing cloures

someFunctionTakesCloures() {

    //       

}



//                    trailing cloures,          ()

someFunctionTakesCloures {

    //       

}



//   trailing cloures  sorted  

sorted(names) {return $0 > $1}



//    

func makeInCrementor(forIncrement amount: Int) -> () -> Int {

    var runningTotal = 0

    func incrementor() -> Int {

        runningTotal += amount

        return runningTotal

    }

    return incrementor

}

//    incrementor     ,