//获取entity中的数据
func fetchFiles() {
//第一步,获取总代理
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
//第二步,获取对象管理上下文
let managedContext = appDelegate.managedObjectContext
//第三步,获取entity的请求对象
let fetchRequest = NSFetchRequest(entityName: "Article")
//第四步,获取结果集
let fetchResults = managedContext?.executeFetchRequest(fetchRequest, error: nil) as [NSManagedObject]?
//第五步, 赋值
if (fetchResults != nil) {
filesTable = fetchResults!
for result in filesTable {
let name = result.valueForKey("name") as String?
let content = result.valueForKey("content") as String?
NSLog("\(name), \(content)\n")
}
}
}
时间: 2024-10-02 04:59:30