2016-08-23 3 views
0

내가 가지고 내가 type 특성에 술어를 적용 할 필요가 Section 객체 술어 - 신속한

class Section: NSObject { 

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

의 배열

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있다 속성은 문자열의 enum입니다.

+1

왜 술어 대신'.filter'를 사용합니까? – Tj3n

+0

그래, 우리는 할 수있다. 그러나 이런 식으로 처리하는 것이 궁금하다. – Saif

답변

1

오류 메시지가 모든 것을 말한다. 열거 형에서 Objective-C 유형으로의 매핑이 없으므로 속성이 "핵심 가치 코딩 준수"가 아닙니다. 자동으로 매핑하려면 더 간단한 enum : Int 유형을 사용해야합니다.

+0

@ Tj3n이 제안한대로'NSPredicate' 대신'.filter'를 사용했다. – Saif

0

"% d"대신 "% @"을 사용하십시오.

하자 술어 = 자 NSPredicate (형식 : "SELF.type == %의 @", SectionType.Name.rawValue는)