I am writing an application that makes a lot of http requests and then parses their JSON response.
I want to parse the JSON asynchronously so as to avoid blocking the User Interface. After parsing, the Model should be changed according to the JSON received. My ViewControllers are Key-Value-Observing my Model Classes, so as to refresh instantly.
My question is: Is it safe to parse the JSON and change my model in a background thread? When the model changes UI updates will be fired. I would really really like to avoid using locks because it will be too complicated for me. Is my solution safe? Any ideas on how to parse asynchronously and change the model safely without using threads at all?
You don't have to write your own locks. Just use atomic properties in your model and you're threadsafe.
Yes, that is what properties do:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW2