let view1 = UIView()
view1.isKind(of: UIView.self)
view1.isMember(of: UIView.self)
let number1: Int = 10
let numberIsInt = (number1 is Int) ? true : false
let string = "Hello World!"
let array = [1, 2, 3, 4, 5, 6]
let dict = ["1": 1, "2": 2, "3": 3]
let view = UIView()
let data = Data()
func judgmentClass(_ obj: Any) {
let mirrorType = Mirror(reflecting: obj).subjectType
if mirrorType == String.self {
//...
} else if mirrorType == Array<Int>.self {
//...
} else if mirrorType == Dictionary<String, Int>.self {
//...
} else if mirrorType == UIView.self {
//...
} else {
//...
}
}
网友评论