Frage

If I created two objects and executed the same method on those two objects, is the pointer for those two methods of different instantiations of the same object type, the same.

Example:

NSObject *obj1 = [NSObject new];
NSObject *obj2 = [NSObject new];

[obj1 doSomething];
[obj2 doSomething];

Is the pointer to doSomething the same for both of those objects. How could I prove it is or it isn't? I've been told it is.

War es hilfreich?

Lösung

It is - there would be no point in creating a new function pointer for each object. (And it would also be ridiculously hard to do so.)

You can observe this by e. g. reading the NSObject class reference. This class has a method called instanceMethodForSelector:. This is a class method, so it can only return a function pointer which is not dependent on instances, only on the class (and the selector, of course).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top