Ok, let's imagine the following class
Now, doing this we would have a problem. Our problems are on lines 58&65. Let's take line 58.
We are wrapping mutating of our NSMutableArray in a dispatch_async call to a serial queue. However, when we call [self myMutableArray]
, that will dispatch_sync to the same serial queue. That dispatch code will never be called, because our first dispatch code will not complete first.
What is the ideal solution to this
1) remove - (NSMutableArray *)myMutableArray
and - (void)setMyMutableArray:(NSMutableArray *)myMutableArray
. Keep all reads in dispatch_sync to the serial queue, and all writes in dispatch_async calls to the serial queue... with the exception of the setter and getter. Is it common to never wrap the setter and getter?
That's actually the only solution I believe.
So my question is... is it common practice to never wrap the getter and setter internals in dispatch's to your serial queue?