I have method which makes UI changes in some cases.
For example:
-(void) myMethod {
if(someExpressionIsTrue) {
// make some UI changes
// ...
// show actionSheet for example
}
}
Sometimes myMethod
is called from the mainThread
sometimes from some other thread
.
Thats is why I want these UI changes to be performed surely in the mainThread
.
I changed needed part of myMethod
this way:
if(someExpressionIsTrue) {
dispatch_async(dispatch_get_main_queue(), ^{
// make some UI changes
// ...
// show actionSheet for example
});
}
So the questions:
- Is it safe and good solution to call
dispatch_async(dispatch_get_main_queue()
in main thread? Does it influence on performance? - Can this problem be solved in the other better way? I know that I can check if it is a main thread using
[NSThread isMainThread]
method and calldispatch_async
only in case of other thread, but it will make me create one more method or block with these UI updates.