Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. # PersistenceService.h
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface PersistenceService : NSObject
  5.  
  6. @property (nonatomic, retain) NSManagedObjectContext *context;
  7.  
  8. -(instancetype) init;
  9. -(void) saveContext;
  10. @end
  11.  
  12. # PersistenceService.m
  13. @implementation PersistenceService
  14.  
  15. -(instancetype) init {
  16. self = [super init];
  17.  
  18. if (self) {
  19. self.context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
  20. self.context.parentContext = [DataManager sharedInstance].managedObjectContext;
  21. }
  22.  
  23. return self;
  24. }
  25.  
  26. -(void) saveContext {
  27. NSManagedObjectContext *context = self.context.parentContext;
  28.  
  29. [self.context performBlock:^{
  30.  
  31. NSError *error;
  32. [self.context save:&error];
  33.  
  34. [context performBlock:^{
  35. NSError *error;
  36. [context save:&error];
  37.  
  38. [context.parentContext performBlock:^{
  39. NSError *error;
  40. [context.parentContext save:&error];
  41.  
  42. }];
  43. }];
  44. }];
  45.  
  46. }
  47.  
  48. @end
  49.  
  50. # Synchronizer.m
  51. -(void) synchronize {
  52. NSArray *pseudoLeads = [[[PseudoLeadPersistenceService alloc] init] getAllParentPseudoLeads];
  53. if (pseudoLeads) {
  54. PseudoLeadDAO *pseudoLead = [pseudoLeads objectAtIndex:0];
  55. if ([pseudoLead.type isEqualToNumber:[NSNumber numberWithInt:Capture]]) {
  56. CaptureSyncService *service = [[CaptureSyncService alloc] initWithDelegate:self andPseudoLead:pseudoLead];
  57. [service executeRequest];
  58. } else {
  59. HotleadSyncService *service = [[HotleadSyncService alloc] initWithDelegate:self andPseudoLead:pseudoLead];
  60. [service executeRequest];
  61. }
  62. }
  63. }
  64.  
  65. # PseudoLeadPersistenceService.m
  66. -(void) deletePseudoLeadById:(NSNumber *)pseudoLeadId andEventId:(NSNumber *)eventId {
  67. PseudoLeadDAO *pseudoLeadDAO = [PseudoLeadDAO findPseudoLeadById:pseudoLeadId andEventId:eventId inContext:self.context];
  68. [self.context deleteObject:pseudoLeadDAO];
  69. [self saveContext];
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement