ここで聞きたいことがあります。オブジェクトをマッピングして RKResponseDescriptor に追加したところ、機能しましたが、ここに問題があります。JSON からのデータが異なる場合、既に作成されているオブジェクトにマッピングされません。うまくマッピングされていないことに気付きました。
// Setup our object mappings
RKObjectMapping *applicationMapping = [RKObjectMapping mappingForClass:[ApplicationSettings class]];
[applicationMapping addAttributeMappingsFromDictionary:@{
@"filterRead" : @"filterRead",
@"filterUserComments" : @"filterUserComments"
}];
RKObjectMapping *categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"id" : @"categoryID",
@"title" : @"title",
@"slug" : @"slug"
}];
RKObjectMapping *commentMapping = [RKObjectMapping mappingForClass:[Comment class]];
commentMapping.forceCollectionMapping = YES;
[commentMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"comments"];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"(coments).id" : @"commentID",
@"(comments).date" : @"createdDate",
@"(comments).content" : @"comment"
}];
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[Error class]];
[errorMapping addAttributeMappingsFromDictionary:@{
@"error" : @"error",
@"status" : @"status"
}];
RKObjectMapping *postMapping = [RKObjectMapping mappingForClass:[Post class]];
postMapping.forceCollectionMapping = YES;
[postMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"posts"];
[errorMapping addAttributeMappingsFromDictionary:@{
@"id" : @"postID",
@"title" : @"title",
@"content" : @"content",
@"date" : @"createdDate",
@"modified" : @"modifiedDate"
}];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:@{
@"nonce" : @"nonce",
@"cookie" : @"cookie",
@"username" : @"userName",
@"email" : @"email"
}];
// Register our mappings with the provider using a response descriptor
RKResponseDescriptor *userResponse = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *applicationResponse = [RKResponseDescriptor responseDescriptorWithMapping:applicationMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *categoryResponse = [RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *commentResponse = [RKResponseDescriptor responseDescriptorWithMapping:commentMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *errorResponse = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *postResponse = [RKResponseDescriptor responseDescriptorWithMapping:postMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
userResponse,
postResponse,
errorResponse
]] ;
編集番号1:
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
errorResponse,
postResponse,
userResponse
]] ;
この場合、ユーザーの JSON データはマップできますが、もう一方はマップできません。つまり、オブジェクトをこのようにマッピングできますか? responseDescriptors の順序が変更され、オブジェクトが一番下にマップされたためです。
前に下手な英語でごめんなさい