这是一个fetch,它将为我带来一个特定实体的数据,但是在swift 2中我需要它在swift 3中。
func fetchProfile(){
let fetchRequest = NSFetchRequest(entityName: "Perfil")
do {
let result = try moc.executeFetchRequest(fetchRequest)
for managedObject in result {
if let name = managedObject.valueForKey("name")
{
oProfile.oProfile_Name = (name as! String)
}
}
} catch {
let fetchError = error as NSError
print(fetchError)
}
}
答案 0 :(得分:0)
在Swift 3中NSFetchRequest
是通用类型
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Perfil")
do {
let result = try moc.executeFetchRequest(fetchRequest) as! [NSManagedObject]
...
为了利用泛型类型,强烈建议使用NSManagedObject
子类。