
var someAny: Any = 100 // Int 타입의 값 할당
someAny = "어떤 타입도 수용 가능합니다." // String 타입으로 변경
someAny = 123.12 // Double 타입으로 변경
class SomeClass {} // 클래스 정의
var someAnyObject: AnyObject = SomeClass() // SomeClass의 인스턴스를 AnyObject로 할당
// someAny = nil // 오류 발생: Any는 nil을 받을 수 없음
// someAnyObject = nil // 오류 발생: AnyObject는 nil을 받을 수 없음
var integers: Array<Int> = Array<Int>() // 빈 Int 배열 생성
integers.append(1) // 배열에 값 추가
integers.append(100) // 배열에 또 다른 값 추가
print(integers.contains(100)) // true: 100이 배열에 포함되어 있는지 확인
integers.remove(at: 0) // 인덱스 0의 값 제거
print(integers.count) // 1: 현재 배열의 요소 개수 출력
빈 배열은 [] 로 생성할 수 있으며, 불변 배열은 let으로 선언할 수 있습니다.
let immutableArray = [1, 2, 3] // 불변 배열 생성
// immutableArray.append(4) // 오류 발생: 불변 배열에 요소 추가 불가능
var anyDictionary: Dictionary<String, Any> = [String: Any]() // 빈 Dictionary 생성
anyDictionary["someKey"] = "value" // 키-값 쌍 추가
anyDictionary["anotherKey"] = 100 // 또 다른 키-값 쌍 추가
print(anyDictionary) // 현재 Dictionary 출력
anyDictionary.removeValue(forKey: "anotherKey") // 특정 키의 값 제거
print(anyDictionary) // 수정된 Dictionary 출력
var integerSet: Set<Int> = Set<Int>() // 빈 Set 생성
integerSet.insert(1) // 값 추가
integerSet.insert(100) // 값 추가
integerSet.insert(99) // 값 추가
integerSet.insert(99) // 중복 삽입은 무시됨
let setA: Set<Int> = [1, 2, 3, 4, 5] // Set A 생성
let setB: Set<Int> = [3, 4, 5, 6, 7] // Set B 생성
let union: Set<Int> = setA.union(setB) // 합집합 계산
let intersection: Set<Int> = setA.intersection(setB) // 교집합 계산
let subtracting: Set<Int> = setA.subtracting(setB) // 차집합 계산