2017-09-28 2 views
0

속성 이름을 기반으로 레코드를 가져 오려고합니다.코어 데이터 가져 오기 요청 오류

나는 비슷한 문제를 검색하려고하지만 난 질문을 게시하고, 그래서 해결책을 찾을 수 없습니다입니다 ...

만 가져 오는 동안 나는 예외를 가지고 :

[error] error: exception handling request: <NSSQLFetchRequestContext: 0x1c019a270> , keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8> with userInfo of (null) 
CoreData: error: exception handling request: <NSSQLFetchRequestContext: 0x1c019a270> , keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8> with userInfo of (null) 
2017-09-28 19:03:36.725060+0530 app[9684:891158] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8>' 

내 코드 :

let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: Entity) 

    if let predic = predicate_str{ 
     let predicate = NSPredicate(format: predic) 
     fetchRequest.predicate=predicate 
    } 

    do { 
     let arr = try appsession.managedObjectContext.fetch(fetchRequest) //CRASHED 


     // success ... 
    } catch let error as NSError { 
     // failure 
     print("Fetch failed: \(error.localizedDescription)") 
     return(nil,error) 
    } 

, 감사합니다

+1

'predicate_str'이란 무엇입니까? '엔티티 '란 무엇입니까? – jrturton

+0

@jrturton, 엔티티는 "대답"& predicate_str = "imagePath LIKE [c] audio_1.m4a" – nirav

답변

1

조건 자 문자열을 잘못 작성하고 있습니다. 값은 내부 따옴표해야 일치하는, 그래서 당신은 이런 식으로 구축 할 것 : 다음과 같은 조건 문자열로 확인

let predicate = NSPredicate(format: "%K LIKE[c] %@", "imagePath", "audio1.m4a") 

:

imagePath LIKE[c] "audio1.m4a" 

참고 값 당신 '주위에 따옴표 re 매칭, 그리고 애트리뷰트 이름 주위에 따옴표가 없다. 현재의 술어가 imagePath 속성의 값이 audio1.m4a 속성과 같고 작동하지 않는 레코드를 찾으려고합니다.

+0

감사합니다. 작동합니다! – nirav

관련 문제