2015, Building Better Apps with Value Types in Swift
1. 참조 의미론(Reference semantics)
온도 클래스(A Temperature Class)
class Temperature {
var celsius: Double = 0
var fahrenheit: Double {
get { return celsius * 9 / 5 + 32 }
set { celsius = (newValue - 32) * 5 / 9 }
}
}
let home = House()
let temp = Temperature()
temp.fahrenheit = 75
home.thermostat.temperature = temp
temp.fahrenheit = 425
home.oven.temperature = temp
home.oven.bake()



Cocoa와 Objective-C에서의 방어적 복사

2. 불변성(Immutability)
Mutation 제거
불변 온도 클래스
에라토스테네스의 체


코코아 터치의 불변성
3. 값 의미론(Value semantics)
값 타입의 구성
값 유형은 값으로 구분됩니다.
온도의 값 의미론

Race Condition으로부터의 자유


4. 값 타입 연습(Value types in practice)






5. 값 타입과 참조 타입 섞기(Mixing value types and reference types)

불변 객체의 참조

불변 객체의 참조와 Equatable


가변 객체의 참조

Copy-on-Write




다각형에서의 경로 형성
값 타입으로 실행 취소 구현하기




Reference
Last updated