views:

185

answers:

2

In Objective-C, you can declare a block as being synchronized on some object by using the @synchronized construct. It would look something like this:

@synchronized (self) {
    // Do something useful
}

However, I'm curious what exactly self is referring to when you have a static method (+ instead of -). I tried looking through the Apple docs, and they allude to it being OK, but don't really explain it. I know it works, I'm just curious what it means.

+5  A: 

self inside of a class (static) method refers to the class object.

Wevah
Thank you. I know there was something simple I was missing.
Itay
+3  A: 

In Objective-C self is determined by context. In an instance method, that would be the instance being called. In a static method, it would be the class object itself (i.e. the result of [self class] in an instance method)

Aviad Ben Dov