|Class |Struct |Enum type |Reference |Value |value Subclassing |O |X |X Extension |O |O |O
///struct와 class의 비교///
struct ValueType {
var property = 1
}
class ReferenceType {
var property = 1
}
let firstStructInstance = ValueType()
var secondStructInstance = firstStructInstance
secondStructInstance.property = 2
print("first struct instance property : \(firstStructInstance.property)") // 1 ///struct는 값을 복사하기 때문에 원본 값이 변하지 않음
print("second struct instance property : \(secondStructInstance.property)") // 2
let firstClassReference = ReferenceType()
var secondClassReference = firstClassReference
secondClassReference.property = 2
print("first class reference property : \(firstClassReference.property)") // 2 ///class는 값을 참조하기 때문에 원본 값(참조값)이 2로 바뀜
print("second class reference property : \(secondClassReference.property)") // 2
스위프트 대부분의 데이터 타입은 구조체임
public struct Int public struct Double public struct String public struct Dictionary<Key : Hashable, Value > public struct Array<Element> public struct Set<Element : Hashable>