0

我在使用 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);
}];

任何人都可以看到任何会导致这不起作用的错误吗?

4

1 回答 1

0

在与开发人员进行长时间的交谈后,它归结为没有分配给实体的主键。

我必须在 Xcode 中选择实体,然后在 userInfo 部分中添加了'relatedByAttribute':'clientMasterId'.

clientMasterId根据 MR,现在将是我的 primaryKey

于 2013-08-22T02:28:37.017 回答