gpt4 book ai didi

ios - 从 NSOrderedSet 中提取 NSManagedObject 属性值

转载 作者:行者123 更新时间:2023-11-28 11:13:43 26 4
gpt4 key购买 nike

我有一个初始化程序,它接受一个 Strings 数组作为参数。与其重写类并冒着破坏事物的风险,我更愿意为初始化程序提供它想要的东西。

我正在尝试从存储在 NSOrderedSet 中的 NSManagedObjects 中提取 NSStrings

这是我尝试过的:

    let soundsToPlay = sequenceToPlay.sounds as NSOrderedSet
for element in soundsToPlay {
// this prints out the object in console
print("\(element)")
// this, doesn't give me accessors for the sound object
// print("\(element.fileName)")
}

我缺少一些基本的东西,但我不确定是什么。我将如何枚举 NSOrderedSet 中的对象并提取集合中包含的实体的属性值?

最佳答案

我建议阅读有关 KVC(键值编码)的文档,因为您可以将其编写为一行代码:

let filenameArray = soundsToPlay.valueForKey("fileName").array()

valueForKey 的调用将返回字符串的 NSOrderedSet,然后您可以通过调用 array() 将其转换为数组>

关于ios - 从 NSOrderedSet 中提取 NSManagedObject 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33262883/

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