Skip to content

jakeheis/CKSynchronizedObjects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CKSynchronizedObjects

An easy way to keep arrays and dictionaries synced with a file. Start by intializing an arrray or dictionary with the file you want it to stay syncrhonzied with. After that, any changes you make to the synchronized object are automatically saved, in either .plist format or archived data created by NSKeyedArchiver.

###Usage Intializing:

+(CKSynchronizedArray *)synchronizedArrayWithFilePath:(NSString *)fileName;
+(CKSynchronizedArray *)synchronizedArrayWithFilePath:(NSString *)fileName synchronizationType:(CKFileSynchronizationTypes)syncType;

+(CKSynchronizedDictionary *)synchronizedDictionaryWithFilePath:(NSString *)filePath;
+(CKSynchronizedDictionary *)synchronizedDictionaryWithFilePath:(NSString *)filePath synchronizationType:(CKFileSynchronizationTypes)syncType;

CKSynchronizedObjects provide some basic hooks into their underlying objects:

// Array
-(NSUInteger)count;
-(id)objectAtIndex:(NSUInteger)index;

-(void)addObject:(id)anObject;
-(void)insertObject:(id)anObject atIndex:(NSUInteger)index;
-(void)removeLastObject;
-(void)removeObjectAtIndex:(NSUInteger)index;
-(void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;

// Dictionary
-(NSUInteger)count;
-(id)objectForKey:(id)aKey;

-(void)removeObjectForKey:(id)aKey;
-(void)setObject:(id)anObject forKey:(id <NSCopying>)aKey;
-(void)setVal:(id)value forKey:(NSString *)aKey;

After any of these methods are called on the underlying object (array/dictionary), it is automatically synced with the file you specified during initialization.

Any more advanced changes you need to make can be done easily as well:

[syncArray changeArrayAndSynchronize:^(NSMutableArray *array) {
        [array exchangeObjectAtIndex:3 withObjectAtIndex:1];
}];

After this block is executed, the object is also automatically synced.

About

An easy way to keep arrays and dictionaries synced with a file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published