我正在尝试从我的User
类中获取数据:
@objc(User)
class User: NSManagedObject {
// Attributes
@NSManaged var cAge: Int16
@NSManaged var rAge: Int16
@NSManaged var cIncome: Int64
@NSManaged var rIncome: Int64
@NSManaged var state: String
@NSManaged var returnRate: Float
}
这是我的提取呼叫:
let user = User.mr_findAll()! as! [User]
print(user)
这是print(user)
的输出:
[<User: 0x2812da300> (entity: User; id: 0x2831da740 <x-coredata:///User/t34A918DC-3B79-4ECC-91EF-16F658B20B8A2> ;
data: {
cAge = 23;
cIncome = 125086;
rAge = 50;
rIncome = 365048;
returnRate = "0.78";
state = In;
})]
我如何只检索数据,而不是所有其他信息?
答案 0 :(得分:0)
我需要遍历结果以从User类中提取属性。
let users = User.mr_findAll()! as! [User]
for user in users{
print(user.cAge)
}