我有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
屬性,這是字符串的枚舉。
請幫我解決問題
爲什麼不用'.filter'代替謂詞? – Tj3n
是的,我們可以,但只是好奇地得到它這樣做 – Saif