我有一个 AFNetworking 调用,它正在调用我的 API 并存储结果。我有一个类似的电话,以这种方式工作得很好。然而,对于这个,它似乎只存储最后一项。
[client getPath:@"GetItemsByFilter/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Operation: %@", operation);
NSLog(@"Response: %@", responseObject);
NSArray *customerFieldResults = [responseObject valueForKeyPath:@"details.items"];
NSLog(@"Results: %@", customerFieldResults);
__block NSArray *array;
@try {
[CustomerFields MR_truncateAll];
array = [CustomerFields MR_importFromArray:customerFieldResults];
NSLog(@"done setting array: %@", array);
} @catch (NSException *e) {
NSLog(@"Exception: %@", e);
} @finally {
NSLog(@"tc done");
}
NSLog(@"Array 1: %@", array);
[[NSNotificationCenter defaultCenter] postNotificationName:kCustomerFieldSetComplete object:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Operation: %@", operation);
NSError *jsonError;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[[error localizedRecoverySuggestion] dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&jsonError];
NSLog(@"Error: %@", [error localizedRecoverySuggestion]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Api Error: %@", [dict valueForKey:@"status"]] message:[dict valueForKey:@"statusMessage"] delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", @"Okay button") otherButtonTitles:nil];
[alert show];
}];
当我使用上下文执行此操作时,它甚至不会保存项目。当收到此信息完成时,我将发送通知,并且在该通知中,我正在显示来自[CustomerFields findAll]
. 仅找到一个带有 的项目[CustomerFields findAll]
。
Array1 显示了完整的项目列表,但是一旦我回到另一个控制器,它只会返回数组中的最后一个项目。此外,如果我将其包装在 a 中saveWithBlock
,它将不会在另一个控制器中看到任何项目。
为什么当我执行时它只显示导入的最后一条记录findAll
?