我正在使用JSQCoreDataKit(https://github.com/jessesquires/JSQCoreDataKit)从Coredata中获取数据
因此,当我获取时,它返回AnyObject
类型的result.objects如何将其转换为对象数组,以便我可以访问id和name等属性。
internal static func GetCountryEntityList(entityname: String, predicate: String)->AnyObject{
let model = CoreDataModel(name: module, bundle: NSBundle(identifier: bundle)!)
let stack = CoreDataStack(model: model)
let privateStack = CoreDataStack(model: model, storeType: NSInMemoryStoreType, options: nil, concurrencyType: .PrivateQueueConcurrencyType)
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
let countryEntity = entity(name: entityname, context: stack.managedObjectContext)
let request = FetchRequest<Country>(entity: countryEntity)
if predicate != ""{
let predicate = NSPredicate(format: predicate)
request.predicate = predicate
}
request.sortDescriptors = [sortDescriptor]
let result = fetch(request: request, inContext: stack.managedObjectContext)
if !result.success {
println("Error = \(result.error)")
}
return result.objects
}
这是使用JSQCoreData
从CoreData获取数据的代码 var countryListNew = [Country]()
countryListNew = CoreDataManager.GetCountryEntityList("Country", predicate: "") as! [Country]
以上是我的控制器中的代码
这就是结果。对象是
这就是countryListNew
请参阅我无法访问姓名或身份证件
国家级