Object-c synchronized return

- (id) methodThatReturnsSomething
{
    @synchronized (self) {
        return nil;
    }
}

When I do this on Xcode, it returns a warning to me: "Control reaches the end of the non-void function"

Are there any problems with this code?

+3
source share
3 answers

This is a compiler warning due to a bug in some versions of the compiler that are fixed in other / later versions of the compiler.

In this case, yes, you really stumbled upon a compiler error.

+11
source

, :
@synchronized , . return, .

+1

I do not understand what you want to do in your code, but

- (id)methodThatReturnsSomething
{
    @synchronized(self) {
    }
    return nil;
}

should have the same effect (delaying the return until the lock associated with it is released self), without warning the compiler.

But: what did you want to do? So you do not need to bet @synchronized.

0
source

Source: https://habr.com/ru/post/1751434/


All Articles