Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is circular method calling allowed?

Tags:

objective-c

I am calling a method from two threads and thought I try this:

- (void)hideEnterButton
{
    if ([NSThread isMainThread])
    {
        enterButton.hidden = YES;
    }
    else
    {
        [self performSelectorOnMainThread:@selector(hideEnterButton) withObject:nil waitUntilDone:NO];
    }
}

Reason for this is that I understand that all GUI handling must be done on the main thread. Will this work?

like image 411
Cub71 Avatar asked Dec 22 '22 07:12

Cub71


2 Answers

The proper term is recursive, not circular and yes, it's perfectly fine to do this.

like image 183
omz Avatar answered Jan 10 '23 18:01

omz


Yes, this is completely valid. I have used this exact method before, and it works very well. The only problem is, any code using this cannot assume that the button is hidden after it returns because it doesn't wait for the call to finish. If that won't be a problem, use it as is. If it will, simply pass YES for waitUntilDone: instead.

like image 29
ughoavgfhw Avatar answered Jan 10 '23 17:01

ughoavgfhw