通过反射机制可以不用继承(当然也可以继承)NSObject就可以获取到属性列表,而如果要通过OC的RunTime获取到属性列表必须继承NSObject
class Person{
privatevarname :String? ="piaojin"
letage :Int=20
varheight :Float=100
varw :Float?
varclosure : (String) -> (String) = {
(str:String)in
return"piaojin"
}
vararr : [Any]? = [Any]()
vara :Int{
get{
return8
}
set{
}
}
funcsayHello(){
}
}
letperson =Person()
//创建反射机制的相关对象
letm =Mirror(reflecting:person)
//获取到属性列表和对应的值
for(key,value)inm.children{
print("key:\(String(describing: key)),value:\(value),type:\(type(of: value))")
}
static属性和计算属性是获取不到的