Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PersistenceService.h
- #import <Foundation/Foundation.h>
- @interface PersistenceService : NSObject
- @property (nonatomic, retain) NSManagedObjectContext *context;
- -(instancetype) init;
- -(void) saveContext;
- @end
- # PersistenceService.m
- @implementation PersistenceService
- -(instancetype) init {
- self = [super init];
- if (self) {
- self.context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
- self.context.parentContext = [DataManager sharedInstance].managedObjectContext;
- }
- return self;
- }
- -(void) saveContext {
- NSManagedObjectContext *context = self.context.parentContext;
- [self.context performBlock:^{
- NSError *error;
- [self.context save:&error];
- [context performBlock:^{
- NSError *error;
- [context save:&error];
- [context.parentContext performBlock:^{
- NSError *error;
- [context.parentContext save:&error];
- }];
- }];
- }];
- }
- @end
- # Synchronizer.m
- -(void) synchronize {
- NSArray *pseudoLeads = [[[PseudoLeadPersistenceService alloc] init] getAllParentPseudoLeads];
- if (pseudoLeads) {
- PseudoLeadDAO *pseudoLead = [pseudoLeads objectAtIndex:0];
- if ([pseudoLead.type isEqualToNumber:[NSNumber numberWithInt:Capture]]) {
- CaptureSyncService *service = [[CaptureSyncService alloc] initWithDelegate:self andPseudoLead:pseudoLead];
- [service executeRequest];
- } else {
- HotleadSyncService *service = [[HotleadSyncService alloc] initWithDelegate:self andPseudoLead:pseudoLead];
- [service executeRequest];
- }
- }
- }
- # PseudoLeadPersistenceService.m
- -(void) deletePseudoLeadById:(NSNumber *)pseudoLeadId andEventId:(NSNumber *)eventId {
- PseudoLeadDAO *pseudoLeadDAO = [PseudoLeadDAO findPseudoLeadById:pseudoLeadId andEventId:eventId inContext:self.context];
- [self.context deleteObject:pseudoLeadDAO];
- [self saveContext];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement