如何使用 Swift 4 的 MagicalRecord 正确获取数据?
How can I properly fetch data using MagicalRecord for Swift 4?
我正在尝试从我的 User
class:
中获取数据
@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;
})]
我怎样才能只检索数据,而不检索所有其他信息?
我需要遍历结果以从用户中提取属性 class。
let users = User.mr_findAll()! as! [User]
for user in users{
print(user.cAge)
}
我正在尝试从我的 User
class:
@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;
})]
我怎样才能只检索数据,而不检索所有其他信息?
我需要遍历结果以从用户中提取属性 class。
let users = User.mr_findAll()! as! [User]
for user in users{
print(user.cAge)
}