AFNetworking的魔法记录导入问题

时间:2013-08-21 20:26:48

标签: ios objective-c afnetworking magicalrecord

我遇到了Magical Record的问题。我有一个项目数组,我需要导入ProviderSearchResult个对象。当我导入它们时,我继续为

获得 EXC_BAD_ACCESS
#24 0x00008770 in __67+[NSManagedObject(MagicalRecord) MR_executeFetchRequest:inContext:]_block_invoke at
MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m:33

我已经搜索了如何解决这个问题的高低,但没有任何工作。我的代码是

ApiClient *client = [ApiClient sharedInstance];

NSDictionary *dataDictionary = [[NSDictionary alloc] initWithObjects:@[searchString] forKeys:@[@"companyName"]];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSString *token = [[[UserManager sharedInstance] getAuthenticationObject] authenticationToken];

NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjects:@[@"json", token, jsonString ]
                                                                   forKeys:@[@"callType", @"token", @"data"]];

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[client getPath:@"GetClientInterfaces/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    NSLog(@"Operation: %@", operation);
    NSLog(@"Response: %@", responseObject);
    NSLog(@"Type: %@", [[responseObject valueForKeyPath:@"details.items"] class]);
    NSLog(@"First: %@", [[responseObject valueForKeyPath:@"details.items"] firstObject]);
    NSArray *providerResults = [responseObject valueForKeyPath:@"details.items"];
    NSLog(@"Results: %@", providerResults);
    __block NSArray *array;
    [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        array = [ProviderSearchResults MR_importFromArray:providerResults inContext:localContext];
    }];
    NSLog(@"Array: %@", array);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    NSLog(@"Operation: %@", operation);
    NSLog(@"Shit: %@", error);
}];

任何人都可以看到任何会导致这种情况无效的错误吗?

1 个答案:

答案 0 :(得分:0)

在与开发人员进行了长时间的对话之后,它归结为未分配给实体的主键。

我必须在Xcode中选择实体,然后在userInfo部分添加了一个键/值'relatedByAttribute':'clientMasterId'

根据MR

clientMasterId现在将成为我的主要关键