I have an array of NSManagedObjects, which is shared by several fragments, some on main queue some inside callback closures. Sometimes while I am clearing this array , other part of code tries to access it to read and show the data on UI and as it sometimes doesn't find data it crashes.
I am considering to use NSLocks to protect this array write or read, however I am not sure if this approach is safe and correct. I am open to suggestions , or correction to this approach.
Apple does not recommend to share same NSManagedObject between different threads:
You should have different copies of the object on different threads.
I think in your case you have 2 problems: