从核心数据读取时获取属性名称和值
Getting both attribute name and value when reading from core data
我在读取核心数据时需要获取属性名称和属性值,有什么简单的方法可以做到这一点吗?
我一直在尝试将我的对象模型中的第一个元素检索为字典,但这给了我一个错误提示:
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
有丰富的API自省。
let activeIndex = retrievedList[0]
for (key, value) in activeIndex.entity.attributesByName {
println("\(key) : \(activeIndex.valueForKey(key as NSString))")
}
我在读取核心数据时需要获取属性名称和属性值,有什么简单的方法可以做到这一点吗?
我一直在尝试将我的对象模型中的第一个元素检索为字典,但这给了我一个错误提示:
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
有丰富的API自省。
let activeIndex = retrievedList[0]
for (key, value) in activeIndex.entity.attributesByName {
println("\(key) : \(activeIndex.valueForKey(key as NSString))")
}