- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
{
if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
{
return nil;
};
NSFetchRequest *fr=[[NSFetchRequest alloc] init];
[fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
[fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
[fr setIncludesPropertyValues:YES];
NSError *err;
NSArray *res=[context executeFetchRequest:fr error:&err];
if (err!=nil)
{
NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
return nil;
}
else
{
if ([res count]<=0)
{
NSLog(@"[res count]<=0");
//NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
return nil;
}
else if([res count]>1)
{
NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
return nil;
}
else //[res count] == 1
{
return [res objectAtIndex:0];
};
};
}