Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSManagedObject *newConnection = [[NSManagedObject alloc] init];
- if(_connection != nil) {
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Connection" inManagedObjectContext:context];
- [request setEntity:entityDesc];
- NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF == %@", _connection.connectionID];
- [request setPredicate:pred];
- NSError *error;
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if([objects count] > 0) {
- newConnection = objects[0];
- }
- }
- else {
- newConnection = [NSEntityDescription insertNewObjectForEntityForName:@"Connection" inManagedObjectContext:context];
- }
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if([objects count]>0) {
- newConnection = objects[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement