Struct, Enum, Tuple, 컬렉션( Array, Dictionary, Set)struct ValueType {
var property = 1
}
//첫 번째 구조체 인스턴스
let firstStructInstance = ValueType()
//두 번째 구조체 인스턴스(첫번째 인스턴스 복사)
var secondStructInstance = firstStructInstance
//두 번째 구조체 인스턴스 프로퍼티값 수정
secondStructInstance.property = 2
//두 인스턴스 간의 영향 없음
print(firstStructInstance.property) //결과 : 1
print(secondStructInstance.property) //결과 : 2
Class, Class의 인스턴스, 클로저class ReferenceType {
var property = 1
}
//클래스 인스턴스 생성(첫 번째 참조 생성)
let firstReferenceType = ReferenceType()
//두 번째 참조변수 생성(첫 번째 참조를 할당)
var secondReferenceType = firstReferenceType
secondReferenceType.property = 2
//두 번째 참조 변수는 첫 번째 클래스 인스턴스를 참조하기 때문에 첫 번째 클래스의 프로퍼티 값도 변경됨
print(firstReferenceType.property) //결과 : 2
print(secondReferenceType.property) //결과 : 2
값 타입
참조 타입