gpt4 book ai didi

ios - 枚举属性的谓词 - swift

转载 作者:行者123 更新时间:2023-11-28 16:15:52 24 4
gpt4 key购买 nike

我有一个 Section 的数组对象

class Section: NSObject {

enum SectionType : String {
case Name = "NAME"
case Address = "ADDRESS"
case Phone = "PHONE"
}
var type : SectionType = .Name
}

我需要在 type 上应用谓词属性

let predicate = NSPredicate(format: "SELF.type == %d", SectionType.Name.rawValue)
let filteredArray = (preferenceSections as NSArray).filteredArrayUsingPredicate(predicate) //CRASH
if filteredArray.count > 0 {

}

应用崩溃 Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Mobile.Section 0x7fb120d33c50> valueForUndefinedKey:]: this class is not key value coding-compliant for the key type.' , 但节对象有 type属性,它是字符串的枚举。

请帮我解决问题

最佳答案

错误消息说明了一切。没有从您的枚举类型到 Objective-C 类型的映射,这意味着该属性不是“键值编码兼容的”。您需要使用更简单的 enum : Int 类型才能自动映射。

关于ios - 枚举属性的谓词 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098075/

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