어떻게 엔티티를 매핑하는 동안 정적 값을 설정합니까?restkit 매핑에 정적 값 설정
"friends": [
{
"id": 123,
"name": "Friend",
},
]
"featured": [
{
"id": 456,
"name": "Some Featured user",
},
]
내 매핑 및 설명은 다음과 같이 :
나는이 같은 JSON 응답을
RKMapping *friendsMapping = [ProjectMappingProvider userMapping];
RKMapping *featuredMapping = [ProjectMappingProvider featuredUserMapping];
RKResponseDescriptor *friendsResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:friendsMapping
method:RKRequestMethodGET
pathPattern:@"/api/users"
keyPath:@"friends"
statusCodes:statusCodeSet];
RKResponseDescriptor *featuredResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:friendsMapping
method:RKRequestMethodGET
pathPattern:@"/api/users"
keyPath:@"featured"
statusCodes:statusCodeSet];
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request
responseDescriptors:@[
friendsResponseDescriptor,
featuredResponseDescriptor]];
... some code emited for readabilty ...
지금 무 friendsResponseDescriptor 및 featuredResponseDescriptors 거의 동일하게 보인다,하지만 난 추가 설정하려는 그에 따라 CoreData 매개 변수. friendsDescriptor를 통해 매핑 된 개체는 섹션이 0이어야하며 추천 된 설명자를 통해 매핑 된 개체는 섹션이 10이어야합니다.
이렇게 할 수 있습니까?
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"User"
inManagedObjectStore:[[DataModel sharedDataModel] objectStore]];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"userId",
@"name": @"name" }];
mapping.identificationAttributes = @[ @"userId" ];
// How can I do somethning like this?
[mapping setValue:@0 forKey:@"section"];
그리고 기능 매핑 :
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"User"
inManagedObjectStore:[[DataModel sharedDataModel] objectStore]];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"userId",
@"name": @"name" }];
mapping.identificationAttributes = @[ @"userId" ];
// How can I do somethning like this?
[mapping setValue:@10 forKey:@"section"];
주 I 사용자 whetever 다른 표시가없는 친구 나 사용자 JSON 자체가 특징입니다. 사용자의 유형 (친구, 추천)을 구별 할 수있는 유일한 방법은 사용자가 설정 한 JSON 응답의 목록입니다. 나중에 섹션을보기 위해 테이블 뷰 컨트롤러의 섹션 속성을 사용합니다.
더 자세히 설명해 주시겠습니까? 추가 데이터를 삽입하는 대리자 메서드를 구현합니다. Reskit에서 특별히 어떤 방법으로 그렇게 할 수 있습니까? 몇 가지 예가 완벽 할 것입니다. – digitaljerry
예를 들어 본 적이 없으며, 그 수준에 참여하고 싶지 않았습니다. 직접 매핑 작업을 실행해야합니다. 더 나은 (확실히 쉽게) 기본값을 가진 다른 엔티티가 될 것입니다 ... – Wain