CocoaPods trunk is moving to be read-only. Read more on the blog, there are 16 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Custom |
ReleasedLast Release | Jul 2015 |
Maintained by David Cortés.
LFSCoreData is an iOS and MacOSX open-source library to help the developer to start Core Data Framework based applications easily. Manage your application database bootstraping, saving in background and mapping from an API easily.
To run the example project; clone the repo, and run pod install
from the Project directory first.
Before starting using LFSCoreData you should read this patterns, and create your entities in xcdatamodel:
Setup your project using LFCoreDataPatterns
NSDictionary *object = @{ name: @"Son", surname: @"Goku" };
User *user = [User importObject:object inContext:[[LFDataModel sharedModel] mainContext]];
// Save context to be persistent
[[LFDataModel sharedModel] saveContext];
...
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[Tweet importFromArray:JSON[@"results"] inContext:[[LFDataModel sharedModel]mainContext]];
// Save context to be persistent
[[LFDataModel sharedModel] saveContext];
[self updateTweetsInUI];
} failure:nil];
...
...
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[LFSaveInBackgroundOperation saveInBackgroundWithBlock:^(NSManagedObjectContext *backgroundContext) {
[Tweet importFromArray:JSON[@"results"] inContext:backgroundContext];
//Save in background already executes save method, so here is not necessary
} completion:^{
[self updateTweetsInUI];
}];
[self updateTweetsInUI];
} failure:nil];
…
...
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[LFSaveInBackgroundOperation saveInBackgroundWithBlock:^(NSManagedObjectContext *backgroundContext) {
Tweet *tweet = [Event objectForIdentifier:JSON[@"id"]
inManagedObjectContext:backgroundContext
forEntityName:[Tweet entityName]];
if (!tweet){
tweet = [Tweet insertInManagedObjectContext:backgroundContext];
}
tweet.tweetID = JSON[@"id"];
tweet.name = [JSON[@"name"] uppercaseString];
} completion:^{
[self updateTweetsInUI];
}];
[self updateTweetsInUI];
} failure:nil];
…
This way you can delete all the elements in the database of the importing entity, except the ones you are importing now.
Can be useful when using LFSCoreData as a cache of your data and this data is volatile.
The usage is like this:
[Tweet importFromArray:yourArrayOfNewObjects
inContext:[[LFSDataModel sharedModel] mainContext]
deleteOtherObjects:YES];
Now you can delete all objects for an specific entity like this:
[Tweet deleteAllObjects];
LAFOSCA STUDIO S.L.
LFSCoreData is available under the MIT license. See the LICENSE file for more info.