Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data driven view iOS app

I am new to objective-c/cocoa programming. I am making an application which is to constantly sync with a server and keep its view updated. Now in a nutshell, heres what I thought of: Initiate an NSTimer to trigger every second or two, contact the server, if there is a change, update the view. Is this a good way of doing it? I have read elsewhere that you can have a thread running in the background which monitors the changes and updates the view. I never worked with threads before and I know they can be quite troublesome and you need a good amount of experience with memory management to get most out of them.

I have one month to get this application done. What do you guys recommend? Just use an NSTimer and do it the way I though of...or learn multithreading and get it done that way (but keep in mind my time frame).

Thanks!

like image 548
user635064 Avatar asked Mar 08 '26 19:03

user635064


1 Answers

I think using separate thread in this case would be too much. You need to use threads when there is some task that runs for considerable amount of time and can freeze your app for some time.

In your case do this:

  1. Create timer and call some method (say update) every N seconds.
  2. in update send asynchronous request to server and check for any changes.
  3. download data using NSURLConnection delegate and parse. Note: if there is probability that you can receive a huge amount of data from server and its processing can take much time (for example parsing of 2Mb of XML data) then you do need to perform that is a separate thread.
  4. update all listeners (appropriate view controllers for example) with processed data.
  5. continue polling using timer.
like image 76
Max Avatar answered Mar 11 '26 07:03

Max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!