title: NSLock + atomic property vs nonatomic
body: <p>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?</p>
  
  <p>As far as I can tell I have two options:</p>
  
  <p><strong>1) NSLock + atomic property</strong></p>
  
  <p>...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.</p>
  
  <p><strong>2) Nonatomic property</strong></p>
  
  <p>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.</p>
  
  <p>What is the best way of doing this?</p>