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
Post a Comment