获取object各个元素的key
2017-07-13 本文已影响0人
PiscesLi
//MARK: - 获取object各个元素的key
public class func getKey() ->Array<Any> {
var ivarNum : u_int = 0
let ivars = class_copyIvarList(self, &ivarNum)
var mArray = Array<Any>()
for index in 0..<numericCast(ivarNum) {
let ivarNameC = ivar_getName(ivars?[index])
let str = String.init(utf8String: ivarNameC!)
mArray.append(str!)
}
free(ivars)
return mArray
}