Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to get data from some where and save it in a NSMutableArray of custom objects that contain that data and info.

Every time the user opens the app the same data is loaded from source and converted to my lovely array with custom objects. This takes a long time (~ 10-20s) and makes the app like a dumb. So what I tried to get the data and display it like in this link

What I tried:

  • save the array with custom objects to a file and load this file on next app start (if found) without a need to create the custom object from scratch again.
  • custom object encode & decode takes a long time at testing. Even if you save it in NSUserDefault.

Before any one start to answer this question plz. Have a look at the sample code and run it to make sure what I mean by retrieving the data and displaying it. in fast time after relaunch the sample and make what I wanna more clear :)

If anyone can make this sample more clear for me I will be thankful.

share|improve this question
    
Are you using Core Data? Where is your large data coming from? Does it really need to be imported every time the user launches the app? –  Amy Worrall Jun 12 '13 at 12:25
    
let's say i'm trying to get all Events from native calendar or get all contacts when the app run then fill the array with custom objects that contain contacts or events detail ??? –  Omarj Jun 12 '13 at 12:58
    
@AmyWorrall like I said before ifI wanna to save it to database it is need to encode and decode and this take a time when array contain more than 3-5k record ? –  Omarj Jun 12 '13 at 13:00
    
I am confused by your question. What exactly is the problem, what are you trying to achieve, and how is it related to the link you've given? –  Alex Jun 13 '13 at 6:23
    
@Alex what i'm trying to achieve is loading my data in the same speed and time this sample do. –  Omarj Jun 13 '13 at 7:29

3 Answers 3

up vote 0 down vote accepted

Thx all :)

I found this simple tutorial that explain some parts of sample code "fetchedResultsController".

and the different is in .pch file where there is ZAssert condition to fetch data when app start and when first time add.

share|improve this answer

I am recommending you a very simple solution which I have used many times and is very efficient too.

  1. Download videos on filesystem if download succeed then write file
  2. path to SQLite next time check if file with same name or same id
  3. exists in SQLite file too If yes then play the video from SQLite
  4. otherwise go to step one.

For this solution you have to create a new manager class which will make sure from where you have to fetch data.

share|improve this answer

In my opinion you only have two reasonable options: 1) the obvious is to use a database store and Core Data to manage your objects. 2) if you don't want to use Core Data, you might store each of your custom objects separately so that you can load them in batches.

If you want to go for the second option you can:

1) Implement the NSCoding protocol on your custom object. (it's just a bit of boilerplate code, very straightforward) 2) After you have loaded the data you can asynchronously save it to disk (this way you won't block the UI). 3) When the app launches, you might load a batch of your objects (e.g. 20, considering that you will only display ~10 at a given point). Then when the user scrolls through your content you can asynchronously load more of it in the same chunks so that they'll be ready to be displayed if/when needed.

This should greatly improve the performance of your app. If you use Core Data, instead, you can have it use a similar behaviour by setting the -[NSFetchRequest fetchBatchSize] property. This will take care of fetching data in batches automatically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.