Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. NSManagedObject *newConnection = [[NSManagedObject alloc] init];
  2. if(_connection != nil) {
  3. NSFetchRequest *request = [[NSFetchRequest alloc] init];
  4. NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Connection" inManagedObjectContext:context];
  5.  
  6. [request setEntity:entityDesc];
  7. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF == %@", _connection.connectionID];
  8. [request setPredicate:pred];
  9. NSError *error;
  10. NSArray *objects = [context executeFetchRequest:request error:&error];
  11. if([objects count] > 0) {
  12. newConnection = objects[0];
  13. }
  14. }
  15. else {
  16. newConnection = [NSEntityDescription insertNewObjectForEntityForName:@"Connection" inManagedObjectContext:context];
  17. }
  18.  
  19. NSArray *objects = [context executeFetchRequest:request error:&error];
  20. if([objects count]>0) {
  21. newConnection = objects[0];
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement