Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @synchronized(self) { ... } in class-function

Accidentally I have been using a @synchronized block with the semaphore self in a class method.

+(void)someFunction {
    @synchronized(self) {
         /* some code */
    }
}

It seems to be valid code, at least the compiler does not give me any bad feedback. My question is: what is self here? As far as I can tell the @synchronized block didn't work, but it didn't crash either.

I'm just asking out of curiousity.

like image 810
Max Avatar asked Mar 22 '12 13:03

Max


1 Answers

self in this instance refers to the class, instead of an instance. In ObjC, classes are themselves objects.

like image 177
FreeAsInBeer Avatar answered Oct 08 '22 07:10

FreeAsInBeer