Yarek T
Yarek T

Reputation: 9925

Looking for suitable datastore on IOS

I'm building an application that has to do a simple search, sort and limit based on dates on a relatively large dataset, about 10000 rows or so.

The data is read only and has to be bundled with the application and can probably be overwritten on update without migration.

I've successfully used binary plists for this previously, but i've never had to search and sort the data, It was always small enough to load completely into memory.

Preloading coreData seems like such a chore, especially since the data will most likely be read only. I've read a couple of blogs describing ways, they all seem to be very hacky.

I guess my question is:

Is there a good way to preload coreData, or is there a way to search and sort data from plists, or are there other methods ?

EDIT: It seems that I have misunderstood what coreData is all about. I have found this line in the source:

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"TestFour.sqlite"];

And i've replaced it with:

NSURL *storeURL = [[NSBundle mainBundle] URLForResource:@"TestFour" withExtension:@"sqlite"];

Simply moving the SQLite database file to the application bundle, which, as a bonus makes it read only and easily updatable by a new application release.

Thank you for all your help with the research.

Upvotes: 2

Views: 182

Answers (5)

Abizern
Abizern

Reputation: 150685

There is little hacky about preloading a Core Data store for an iOS app.

Just create a helper application that shares the same model and writes data to a set location, and then you can take this file and include it into your app bundle.

As an example - I wrote an example project with a desktop app that takes a csv file, loads it into a Core Data store, and reports the location of this file. It then shows how to include this file into the app bundle and use it.

Upvotes: 1

Hal Mueller
Hal Mueller

Reputation: 7655

I recommend you do not reinvent that particular wheel. Core Data is a great match for that size of dataset. UITableview, NSFetchedResultsController, and NSFetchRequest are made for this problem.

A pattern I've used in several projects is to create an auxiliary MacOS tool that reads the legacy format and saves it into a Core Data store.

In your iOS project, include the Core Data store as a resource. When you spin up the Core Data stack in your iOS app, you'll look for the .sqlite file in the main bundle, not in user filespace. If you want to get fancy, you can have a background thread that tries to download an updated version of the datastore; if there's a new version in user filespace, use that instead of the prepackaged one.

The Ray Wenderlich tutorial that Norbert cites depends on undocumented behavior. Writing directly to .sqlite files is specifically not supported.

The auxiliary data loader (Mac) and the viewer (iOS) share the same .xcdatamodel, and (if applicable) the .h/.m files for the NSManagedObject subclasses. You store your data using the same codebase that you'll use to read it. I've built a couple of projects with 100k rows using this approach, and it runs very well.

Upvotes: 2

MCKapur
MCKapur

Reputation: 9157

I would suggest for storing objects (not too much web-server side) I would suggest using AWS as a solution. S3 is good for storing large objects and you can distribute them to worldwide servers using CloudFront, but for smaller objects and a more scalable/fast solution I would use DynamoDB or SimpleDB. It has very comprehensive documentation and sample code thats easy to write and use.

Upvotes: 0

Misha
Misha

Reputation: 5380

I would suggest to integrate SQLite in your app. Even if your data is read-only. You won't need to load all data to memory in order to fetch something. If you need to get sorted data, use appropriate SQL query. In order to update it, again download your data and insert it with appropriate query.

See the following question regarding SQLite tutorials for iOs good-tutorial-for-sqlite3-with-objective-c-iphone

Upvotes: 1

Norbert
Norbert

Reputation: 4291

If it comes to searching and ordering the given data within the application, I'd suggest to either use SQLite or Core Data with a preloaded data set. In the case of the latter, take a look at this.

Upvotes: 3

Related Questions