iphone - Lock a NSMutableArray of an object but not the rest of my object when using GCD -


i have user class has various properties:

@property (strong, nonatomic) nsstring *candid; @property (assign, nonatomic) bool iscandidate; @property (assign, nonatomic) nsinteger responsecode; @property (strong, nonatomic) nsmutablearray *locations; 

etc

one of viewcontrollers may have user property i.e.

@property (strong, nonatomic) user *user; 

and user may passed subsequent viewcontrollers launched modally.

when user object first initialized going send method off in grand central dispatch fill locations array via rest. idea time using app gets screen pick location, list downloaded.

what want lock locations area when gcd using it, have used like

[somelock lock] ... [somelock unlock] 

in past want locations array locked rest of user object's methods , properties accessible main thread. best way achieve this?

i fetch locations in background thread separate array, , assign user when data complete, like:

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{     nsmutablearray *locations;     // ... fill locations ...             dispatch_sync(dispatch_get_main_queue(), ^{         user.locations = locations;         // ... perhaps refresh view or send notification ...     }) }); 

then user.locations accessible on main thread, , either nil or contains fetched locations.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -