除了完成JSON和Model的轉換之外,KakaJSON內部還有很多實用的功能,有些也開放為public接口了
遍歷屬性
struct Cat {
var age: Int = 0
let name: String = ""
}
guard let type = Metadata.type(Cat.self) as? ModelType,
let properties = type.properties else { return }
for property in properties {
print(property.name,
property.type,
property.isVar,
property.ownerType,
property.offset)
// age Int true Cat 0
// name String false Cat 8
}