참은 true
으로, 거짓은 false
로 표현
실행 환경에 따라 값의 범위 변경
UInt 는 양수만 할당 가능
Float 는 32비트
부동소수형이고, Double 은 64비트
부동소수형이다.
둘 다 유니코드 를 사용하며, 큰 따옴표(" ") 를 사용
함수 타입을 제외한 클래스 포함 Swift의 모든 타입 을 지칭하는 키워드
is
로 어떤 타입을 가지고 있는지 확인 후, as
로 형변환하여 사용 가능class Human {
var weight: Double
var tall: Double
init(_ weight: Double, _ tall: Double){
self.weight = weight
self.tall = tall
}
}
var any: Any = Human(13,12)
if any is Human {
if let instance: Human = any as? Human {
print("tall = \(instance)")
}
}
모든 클래스를 지칭하는 프로토콜
null
과 같이 없음
을 의미하는 키워드
Optional
타입의 변수나 상수에만 할당이 가능순서(인덱스)가 있는 리스트 컬렉션
[Int]
가 Array<Int>
와 동일하게 사용
var integers: Array<Int> = Array<Int>()
// var integers: [Int] = Array<Int>()
// var integers: Array<Int> = [Int]()
// var integers: [Int] = [Int]()
// var integers: [Int] = []
integers.append(10)
integers.remove(at: 0)
integers.removeLast()
integers.removeAll()
integers[i]
integers.count
key와 value로 구성된 컬렉션
[String: Any]
가 Dictionary<String, Any>
와 동일하게 사용
var anyDict: Dictionary<String, Any> = Dictionary<String, Any>()
// var anyDict: [String: Any] = [String: Any]()
anyDict["someKey"] = "value"
anyDict.removeKey(forKey: "someKey")
anyDict["someKey"] = nil
순서가 없고 중복된 값이 없는 컬렉션
var integerSet: Set<Int> = Set<Int>()
integerSet.insert(10)
integerSet.remove(value)
integerSet.removeFirst()
integerSet.count
합집합 setA.union(setB)
교집합 setA.intersection(setB)
차집합 setA.substracting(setB)
🧷 참고한 강의 : "iOS 프로그래밍을 위한 스위프트 기초"