A lightweight core data stack with efficient importing and exporting on the side.
Vokoder is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Vokoder"
The bulk of the functionality is in the Core
subspec. If you aren't using any of the data sources, you can just include the Core
subspec.
Data sources to facilitate backing various kinds of views with data from Core Data are in the DataSources
subspec, which is further broken down into:
FetchedResults
contains a basic data source based on a fetched results controller, intended to be used with aUITableView
.PagingFetchedResults
is based onFetchedResults
but supports paged loading.Collection
is based onFetchedResults
, but intended for use with aUICollectionView
.Carousel
(not included by default) is based onFetchedResults
but intended for use with iCarousel (and hence includes it as a dependency).
##Usage
###Setting up the data model
[[VOKCoreDataManager sharedInstance] setResource:@"VICoreDataModel" database:@"VICoreDataModel.sqlite"]; //Saved to Disk
Or
[[VOKCoreDataManager sharedInstance] setResource:@"VICoreDataModel" database:nil]; //In memory data store
###Inserting records
VIPerson *person = [VIPerson vok_newInstance];
[person setFirstName:@"Rohan"];
[person setLastName:@"Panchal"];
[[VOKCoreDataManager sharedInstance] saveMainContextAndWait];
###Querying Records
####Query with basic predicate
NSArray *results = [VIPerson vok_fetchAllForPredicate:nil forManagedObjectContext:nil]; //Basic Fetch
####Query with basic predicate and sorting
NSArray *results = [VIPerson vok_fetchAllForPredicate:nil
sortedByKey:@"numberOfCats"
ascending:YES
forManagedObjectContext:nil];
###Deleting records
VOKCoreDataManager *manager = [VOKCoreDataManager sharedInstance];
[manager deleteObject:person];
[[VOKCoreDataManager sharedInstance] saveMainContextAndWait];
###Saving
[[VOKCoreDataManager sharedInstance] saveMainContextAndWait]; //Saves synchronously
####Saving on background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSManagedObjectContext *backgroundContext = [[VOKCoreDataManager sharedInstance] temporaryContext];
VIPerson *person = [VIThing vok_newInstanceWithContext:backgroundContext];
[person setNumberOfCats:@1];
[[VOKCoreDataManager sharedInstance] saveAndMergeWithMainContext:backgroundContext];
});
Vokoder is available under the MIT license. See the LICENSE file for more info.