ios - What's a proper way to control access to property that stores server call results? -
my class has property gets populated network call. population can triggered action.
what's correct strategy implement access of property, given property can accessed when new result set being fetched server?
e.g.
@interface myclass @property (nonatomic, strong) nsdictionary *data; @end @implement myclass - (void)loaddata { // self.data can accessed when loaddata called. // what's correct strategy controlling access self.data? [self loaddatafromserverwithcompletion:^(nsdictionary *objects) { [self.data removeallobjects]; // populate self.data objects }]; }
what's correct strategy implement access of property, given property can accessed when new result set being fetched server?
the correct strategy? serialize access.
the easiest way mark property atomic
, , self.data = objects;
in completion handler.
your completion should this:
dispatch_async(dispatch_get_main_queue(), ^{ ... tell app reload data ... });
Comments
Post a Comment