开发者

Fastest/preferred method of loading data into Core Data (iOS)

开发者 https://www.devze.com 2023-03-11 23:38 出处:网络
I have a relatively small amount of data (stored in a static text file) that I\'m loading into Co开发者_如何学JAVAre Data in my iOS app.What is the fastest or preferred method of storing static data o

I have a relatively small amount of data (stored in a static text file) that I'm loading into Co开发者_如何学JAVAre Data in my iOS app. What is the fastest or preferred method of storing static data on the device and loading data into Core Data?

I've tried putting the data in XML format and using libxml to load it into Core Data. I've also tried putting the data in CSV format and using basic string parsing to load it into Core Data. Both of these methods seem to take about the same amount of time for a given data set. I noticed a minor load-time reduction by putting the call to NSManagedObjectContext save outside of the loop over the rows (or XML nodes depending on the format).

Please note the data is only loaded the first time the app starts. Also I've tried "create a SQLite db using another utility app then bundle the SQLite db with the current app" based on feedback from this question. However I couldn't get that to work. If that's the best way to do this then I'll try again.

Cheers!


The simplest solution is to load the data into a Core Data persistent SQL store during development. Then include that file in the app bundle itself. Upon first launch, copy the file from the readonly app bundle into the Documents or Library directory. Then open the store as normal. All the data will be in place and ready to go.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号