2013-07-03 2 views
2

코어 데이터 엔티티와 1 : m 하위의 NSJSONSerialization으로 JSON 객체를 어떻게 만들 수 있습니까? 코어 데이터에서 JSON 만들기

JSON로 변환하기 전에 NSDictionary에 요청을 가져 출력하려고

, 나는 어떤 관계 또는 내 응용 프로그램의 충돌 관계에 propertiesToFetch를 설정할 때없이 NSDictionary 평판을 얻을.

이 내 코드입니다 :

NSFetchRequest *request = [NSFetchRequest 
    fetchRequestWithEntityName:@"ContrSector"]; 
request.resultType = NSDictionaryResultType; 
request.propertiesToFetch = @[@"industries"]; 
NSError *error; 
NSArray *result = [self.managedObjectContext 
    executeFetchRequest:request error:&error]; 

어떻게이 작업을 수행하는 올바른 방법이 될 것입니다?

답변

1

propertiesToFetchNSPropertyDescription의 인스턴스를 기대하고, 그래서 교체하려고 @와 "산업"

NSDictionary *attributes = [[NSEntityDescription entityForName"@ContrSector" inManagedObjectContext:self.managedObjectContext] relationshipsByName]; 
NSAttributeDescription *industriesRelationship = [attributes objectForKey:@"industries"]; 

request.propertiesToFetch = @[industriesRelationship]; 

편집 :

: 나는이 문서에서, 이것은 일대 다 관계였다 실현 didnt가 속성 설명은 속성, 즉 관계 또는 표현식을 나타낼 수 있습니다. 속성 이름 또는 관계 설명은 인출 요청 엔터티에있는 설명의 이름과 일치해야합니다.

+1

은 ((많은 관계로 잘못된'와 충돌 ), 이름 산업, isOptional 1, isTransient 0, 개체 ContrSector, renamingIdentifier 산업 ...' – AlexR

+0

그냥 "산업을 사용할 때 충돌이 무엇인지 "? – wattson12

+0

'- [NSSQLToMany foreignEntityKey] : 인식 할 수없는 셀렉터가 인스턴스로 전송 됨 0x100185460' – AlexR

관련 문제