For a loop randomly hanging on executeFetchRequest: error:

I recently ran into some strange problem with my iOS application and have no idea how to do this.

During the first run, there is a method that runs in the background, which loads a list of elements and element attributes from the game and stores them in Core Data for use in subsequent relationships. The part of the import method that processes the elements is as follows:

NSManagedObject *item;
for (TFSchemaItem *tfItem in [bs items]) {
    item = [NSEntityDescription insertNewObjectForEntityForName:@"SchemaItem" inManagedObjectContext:managedObjectContext_];

    NSLog(@"%@", [tfItem itemName]);

    [item setValue:[tfItem itemName] forKey:@"itemName"];
    [item setValue:[NSNumber numberWithInteger:[tfItem defindex]] forKey:@"defindex"];
    [item setValue:[tfItem itemClass] forKey:@"itemClass"];
    [item setValue:[tfItem type] forKey:@"itemType"];
    [item setValue:[tfItem name] forKey:@"tfName"];
    [item setValue:[NSNumber numberWithInteger:[tfItem slot]] forKey:@"itemSlot"];
    [item setValue:[NSNumber numberWithInteger:[tfItem quality]] forKey:@"itemQuality"];
    [item setValue:[[tfItem imageURL] absoluteString] forKey:@"imageURL"];
    [item setValue:[[tfItem largeImageURL] absoluteString] forKey:@"largeImageURL"];
    [item setValue:[NSNumber numberWithInteger:[tfItem craftClass]] forKey:@"craftClass"];
    [item setValue:[tfItem itemDescription] forKey:@"tfDescription"];
    [item setValue:[NSNumber numberWithBool:[tfItem properName]] forKey:@"properName"];

    NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
    NSMutableArray *attrArray = [[NSMutableArray alloc] init];

    for (TFItemAttribute *attr in [tfItem attributes]) {
        [attrArray addObject:[NSNumber numberWithInt:[attr defindex]]];
    }

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"defindex IN %@", attrArray];
    [attrArray release];

    [fetch setEntity:[NSEntityDescription entityForName:@"Attribute" inManagedObjectContext:managedObjectContext_]];
    [fetch setPredicate:predicate];
    [fetch setReturnsObjectsAsFaults:NO];

    NSLog(@"1");
    NSArray *fetchArray = [managedObjectContext_ executeFetchRequest:fetch error:nil];
    NSLog(@"2");

    [item setValue:[NSSet setWithArray:fetchArray] forKey:@"attributes"];
    ...
}

Before this is another loop that is identical, apart from accessing the attribute object via SchemaItem, and you do not need to create any relationships that work fine.

, [managedObjectContext_ executeFetchRequest:fetch error:nil], "1" , "2" . , , .

, , , executeFetchRequest:error: .

- -, ? 2 .

+3
1

, ?

concurrency; . , ( ) . , ( ) , .

Daniel T, concurrency.

, readonly .

+8

All Articles