asynchronous - objective c, notify other threads -
my task download content, parse it, save in database , update ui after completion (or notify user error). used in different parts of application, want extract code separate class , use asynchronous facade. use nsurlconnection handle network tasks. nsurlconnection calls callbacks in separate thread. ui code should run in main thread. store set of blocks call , invoke them main thread dispatch_async, means main thread hardcoded. looks me want reinvent wheel , there should mechanism used in objective c communicate between threads, can't find it. want:
receivers subscribe receive messages given identifier , specifying thread notifications should dispatched.
sender sends message identifier , attached data.
all subscribed receivers message in threads specified.
or there pattern appropriate task?
you can use nsnotificationcenter
communicate between objects running on different thread.and post notification different thread.
see apple nsnotificationcenter documentation
to update ui elements on main thread use [self performselectoronmainthread:@selector(somefunction) withobject:nil waituntildone:no];
Comments
Post a Comment