Created
January 10, 2013 08:24
-
-
Save cvasilak/4500441 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
#import "AGPropertyListStorage.h" | |
@implementation AGPropertyListStorage { | |
NSString* _file; | |
} | |
@synthesize type = _type; | |
+(id) storeWithConfig:(id<AGStoreConfig>) storeConfig { | |
return [[self alloc] initWithConfig:storeConfig]; | |
} | |
-(id) initWithConfig:(id<AGStoreConfig>) storeConfig { | |
self = [super init]; | |
if (self) { | |
// base inits: | |
_type = @"PLIST"; | |
AGStoreConfiguration *config = (AGStoreConfiguration*) storeConfig; | |
_recordId = config.recordId; | |
// TODO: error handling | |
if (config.name == nil) | |
config.name = @"unnamed"; | |
// calculate path | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
_file = [documentsDirectory stringByAppendingPathComponent:config.name]; | |
// if store exists initialize array | |
if ([[NSFileManager defaultManager] fileExistsAtPath:_file]) { | |
_array = [[NSMutableArray alloc] initWithContentsOfFile:_file]; | |
} else { | |
_array = [[NSMutableArray alloc] init]; | |
} | |
} | |
return self; | |
} | |
-(void) persist { | |
[_array writeToFile:_file atomically:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment