I parse the content of a file in order to create a set of NSManagedObject
in a context and save them. This is the method where I do this:
- (BOOL)getEntitiesFromFileInContext:(NSManagedObjectContext *)context
{
BOOL result = YES;
NSMutableArray *entities = [[NSMutableArray alloc] init];
NSString *entitiesFileContent = [FilesManagerHelper readFile:fileName];
if ([entitiesFileContent isEqualToString:@""]) {
result = NO;
}
else {
@autoreleasepool {
entities = [self parseEntitiesFileContent:entitiesFileContent inContext:context];
// If entities.count > 0, some operations here
}
// Save context and reset
[self saveContext:context];
[self clearContext:context];
}
return result;
}
In parseEntitiesFileContent:inContext:
method I insert the NSManagedObject
objects in the context I provide and I also add them to the entities
array.
I'm performing this in an @autoreleasepool
because I found an example doing that, but I'm not sure if it is really necessary... Could somebody explain me what the difference between using @autoreleasepool
and not using it should be?
Thanks so much
EDIT: Should the entities
array be defined inside the @autoreleasepool
block?