Swift 特色

Swift 特色


1.Value Type & Reference Type
2.Protocol Oriented
3.Thinking Functionally

#Book:
Functional Swift


Value Type

Equatable make sense ==
Independernt
data across

Reference Type

Comparing instance makes sense ===
sharing
Instance lifetime is tied to external effects



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

import UIKit
class APersonWhoWantToEatApple{

    var apple: Apple?

    func eatApple()  {

        if var apple = apple {
            apple.bitten += 1
            print(apple.bitten)
        }else{
            print("no apple")
        }
    }

}
//Compare Let Apple & struct Apple  
struct Apple {
    var bitten = 0;
}

let apple = Apple ()

let jonSnow = APersonWhoWantToEatApple()

let tyrionLannister = APersonWhoWantToEatApple()

jonSnow.apple = apple
tyrionLannister.apple = apple
jonSnow.eatApple()
tyrionLannister.eatApple()

WWDC 2015
Build Better

WWDC 2015
Protocol-Oriented Programming in Swift

Thinking Functionally
Function is first-class value

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

XAMPP 使用多PORT來執行不同網頁

IOS GCD多執行緒