//创建数组的类方法
class func propertList() ->Array{
var count:UInt32 = 0
let arr = NSMutableArray()
//获取模型属性, 返回值是所有属性的数组
let list:UnsafeMutablePointer<objc_property_t>! = class_copyPropertyList(self, &count)
for i in 0..count{
//获取属性
let property:objc_property_t = list[Int(i)];
//获取属性名称
let cName = property_getName(property)
// UnsafePointer转成字符串
let name = UnsafeRawPointer(cName)
arr.add(name)
}
//释放属性组
free(list)
return arr.copy() as! Array<Any>
}
网友评论