타입 체킹, How to check type

고양이발냄새·2023년 8월 8일
0
let item = Item()

if item is Item {
    print("object is of Item subclass type")
} else {
    print("object is not of Item subclass type")
}

let myArray: [Int] = [1, 2, 5]
if myArray is Array<Int> {
    print("Indeed it is array")
}
// Generic이므로 타입을 명시해준다

let objectType = type(of: 4)
Int.Type
print("Object type: \(objectType)")

타입 그자체를 저장함

profile
고양이좋아

0개의 댓글

관련 채용 정보