さて、JSONAPIからデータをマッピングするために使用しているこのコードがあります。すべて正常に動作しますが、次のエラーが発生します。
restkit.object_mapping:RKMapperOperation.m:76 Adding mapping error: Cannot map a collection of objects onto a non-mutable collection. Unexpected destination object type '__NSDictionaryI'
これが私がマッピングに使用しているコードです
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
RKObjectMapping *classMapping = [RKObjectMapping mappingForClass:[GradePeriod class]];
[classMapping addAttributeMappingsFromDictionary: @{
@"period" : @"period",
@"class" : @"name",
@"term" : @"term",
@"teacher" : @"teacher",
@"percent" : @"percent",
@"grade" : @"grade",
@"missing" : @"missing",
@"update" : @"update",
@"detail" : @"url"
}];
// Create a Response Descriptor
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:classMapping
pathPattern: nil
keyPath: @"grades"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
NSDictionary *queryParams;
queryParams = [NSDictionary dictionaryWithObjectsAndKeys:username, @"username", password, @"password", nil];
// Retrieve the Data
[objectManager postObject:queryParams
path:@""
parameters:queryParams
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
grades = [NSMutableArray arrayWithArray: [mappingResult array]];
NSLog(@"Loaded Grades: %@", grades);
[self.tableView reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
// Stuff removed for easier reading
}];
成績はNSMutableArray
@property (nonatomic, retain) NSMutableArray *grades;
GradePeriodは次のように定義されます
@property (strong, nonatomic) NSString *period;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *term;
@property (strong, nonatomic) NSString *teacher;
@property (strong, nonatomic) NSString *percent;
@property (strong, nonatomic) NSString *grade;
@property (strong, nonatomic) NSString *missing;
@property (strong, nonatomic) NSString *update;
@property (strong, nonatomic) NSString *url;
何が間違っているのかわかりません。本当にありがとう!