-
-
Save berkus/6002923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RemoteEntity.h | |
// | |
// Created by Christopher Bradford on 5/6/10. | |
// Copyright 2010 INM United. All rights reserved. | |
// | |
@interface RemoteEntity : NSManagedObject | |
{ | |
} | |
@property (nonatomic, retain) NSNumber * remote_update; | |
@property (nonatomic, retain) NSNumber * remote_id; | |
// Helper method for retrieving an instance of a remote entity given its id | |
+ (RemoteEntity *)entityWithRemoteID:(NSNumber *)remote_id; | |
// Helper method for retrieving the EntityDescription of the entity | |
+ (NSEntityDescription *)entityDescription; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RemoteEntity.m | |
// | |
// Created by Christopher Bradford on 5/6/10. | |
// Copyright 2010 INM United. All rights reserved. | |
// | |
#import "RemoteEntity.h" | |
@implementation RemoteEntity | |
@dynamic remote_update; | |
@dynamic remote_id; | |
#pragma mark Core Data Helper Methods | |
+ (RemoteEntity *)entityWithRemoteID:(NSNumber *)remote_id | |
{ | |
NSFetchRequest *req = [[NSFetchRequest alloc] init]; | |
NSEntityDescription *entity = [NSEntityDescription entityForName:NSStringFromClass([self class]) inManagedObjectContext:APP_DELEGATE.managedObjectContext]; | |
[req setEntity:entity]; | |
[req setPredicate:[NSPredicate predicateWithFormat:@"remote_id = %@", remote_id]]; | |
NSError *error; | |
NSArray *entities = [APP_DELEGATE.managedObjectContext executeFetchRequest:req error:&error]; | |
[req release]; | |
if ([entities count] != 0) { | |
return [entities objectAtIndex:0]; | |
} | |
return nil; | |
} | |
+ (NSEntityDescription *)entityDescription | |
{ | |
return [NSEntityDescription entityForName:NSStringFromClass([self class]) inManagedObjectContext:APP_DELEGATE.managedObjectContext]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment