Reputation: 97
I am a new iOS Developer and I am making an iOS App that consumes information from a Restful web service. I am able to get the data from the server, but sometimes the data takes a while to load. There are aspects of the data that don't change all the time (for example, items a store sell), but there are aspects of the data that change everyday (for example, the inventory count of a certain item). I want to store the data that doesn't change all the time into iOS memory. From my research it looks like core data would be the best way to do this.
How can I store the object data that doesn't change all the time into iOS' core data and have it load that data on startup, then get the information that changes all the time later on?
I did some searching and it looks like from my understanding I can utilize Core Data by getting the data, then storing it into what seems like a Database. I can then fetch the preloaded data from the NSManagedObjects and display them on runtime.
Is this a correct approach? Also, if there is a change in the data (selling a new item), will Restkit handle this and store it into core data or do I need to set it up to notice the change?
Thank you for your help!
Upvotes: 1
Views: 1910
Reputation: 1434
With RestKit, you can build a database based on your CoreData model but you can also build with a pre-populated database.
Your objectManager should look like this:
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://your-url.com"];
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"new-database.sqlite" usingSeedDatabaseName:nil managedObjectModel:nil delegate:self];
or like this if you want a copy of a pre-populated database:
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"new-database.sqlite" usingSeedDatabaseName:@"last-database.sqlite" managedObjectModel:nil delegate:self];
Your last-database.sqlite must be integrated like a copy bundle resource.
This system can help you if you don't want to refresh all datas.
Upvotes: 1
Reputation: 10633
Look at the RestKit Examples directory and open the RKTwitterCoreData project. It shows you a system doing exactly what you describe.
Upvotes: 0