I'm fairly new to objective C. If I have a class property that will likely be getting modified during asynchronous events like API calls, what is the best way to make sure that changing the property while it is being accessed by another thread will not cause a crash?
As far as I can tell I have two options:
1) NSLock + atomic property
...but it seems like in this case I would have to lock the property for every read and write, which to me would defeat the purpose of setting it as atomic.
2) Nonatomic property
I could also set it as nonatomic, but then I think I would have to do all reading/writing on the main thread. Is there a way of doing that as a result of an API call? Would a call back to a delegate after a successful API response be on the thread opened for that API call, or would it be back on the main thread? And if it's on a different thread, could I put it back on the main thread? Specifically, I'm worried about an NSArray getting changed while another thread is looping through it.
What is the best way of doing this?