Ios 从核心数据实体获取NSSet
我有一个NSManagedObject类(SearchHistory.swift),它与(Hospital.swift)类有关系 我试图获取NSSet,但它给了我编译错误:使用了未声明的类型“SearchHistory”,尽管我以相同的方式获取其他实体,并且没有任何错误Ios 从核心数据实体获取NSSet,ios,swift,nsmanagedobject,core,nsset,Ios,Swift,Nsmanagedobject,Core,Nsset,我有一个NSManagedObject类(SearchHistory.swift),它与(Hospital.swift)类有关系 我试图获取NSSet,但它给了我编译错误:使用了未声明的类型“SearchHistory”,尽管我以相同的方式获取其他实体,并且没有任何错误 let AppDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let Context: NSMa
let AppDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let Context: NSManagedObjectContext = AppDel.managedObjectContext!
let request = NSFetchRequest(entityName: "SearchHistory")
var search = Context.executeFetchRequest(request, error: nil) as! [SearchHistory] // ERROR HERE :(
for (var x=0; x<search.count; x++) {
let hospitalsArray: NSArray = search[x].hospitals.allObjects
for hospital in hospitalsArray {
println(hospital.hospital_name)
}
}
让AppDel:AppDelegate=UIApplication.sharedApplication().delegate为!AppDelegate
让上下文:NSManagedObjectContext=AppDel.managedObjectContext!
let request=NSFetchRequest(entityName:“SearchHistory”)
var search=Context.executeFetchRequest(请求,错误:nil)为![SearchHistory]//此处出错:(
对于(var x=0;xIf),如果这是真正的错误消息,您在“SearchHistroty”上的某个地方有一个拼写错误。@PhillipMills这是一个拼写错误
let AppDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let Context: NSManagedObjectContext = AppDel.managedObjectContext!
let request = NSFetchRequest(entityName: "SearchHistory")
var search = Context.executeFetchRequest(request, error: nil) as! [SearchHistory] // ERROR HERE :(
for (var x=0; x<search.count; x++) {
let hospitalsArray: NSArray = search[x].hospitals.allObjects
for hospital in hospitalsArray {
println(hospital.hospital_name)
}
}