is
is the type check operator that checks whether an instance is of a certain type. It can be used to check the instance of class
:
class A {
}
let a = A()
if a is A {
print("a is A") // b is B
}
The is
operator can also be used to check the instance of a subclass of class
:
class SubA: A {
}
let subA = SubA()
if subA is SubA {
print("subA is SubA") // subA is SubA
}
if subA is A {
print("subA is A") // subA is A
}
The is
operator can be used to check the instance of struct
:
#programming #ios #mobile #software-development #swift