当我从我的核心数据中读取时,我需要获取属性名称和属性值,有什么简单的方法可以做到这一点吗?
我一直在尝试将我的对象模型中的第一个元素检索为字典,但这给了我一个错误提示:
fatal error: NSArray element failed to match the Swift Array Element type
我的代码是这样的:
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext!
let fetchReq = NSFetchRequest(entityName: "ActiveIndexes")
fetchReq.resultType = NSFetchRequestResultType.DictionaryResultType
receivedList = context.executeFetchRequest(fetchReq, error: nil) as! [ActiveIndexes]
println(receivedList[0])
如有任何建议,我们将不胜感激。
最佳答案
NSManagedObject
具有丰富的内省(introspection) API。
let activeIndex = retrievedList[0]
for (key, value) in activeIndex.entity.attributesByName {
println("\(key) : \(activeIndex.valueForKey(key as NSString))")
}
关于ios - 从核心数据读取时获取属性名称和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28864153/