gpt4 book ai didi

ios - 从核心数据读取时获取属性名称和值

转载 作者:行者123 更新时间:2023-11-29 02:14:50 25 4
gpt4 key购买 nike

当我从我的核心数据中读取时,我需要获取属性名称和属性值,有什么简单的方法可以做到这一点吗?

我一直在尝试将我的对象模型中的第一个元素检索为字典,但这给了我一个错误提示:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com