If I have a method and class like this:
@implementation Animal
-(void) move{
id *object = [object that called move];
}
@end
Say I have two other classes
@implementation C1
...
[self.animal move]
...
@end
@implementation C2
...
[self.animal move]
...
@end
Without passing the instance ‘self’ into move, is their some way to get access to self from move?
You cannot do this in Objective-C, the only work around I could suggest is sending a reference of the sender when you message your class, such as:
Calling:
You can then use the isMemberOfClass: or isKindOfClass: to determine what type of object the sender is, isKindOfClass will return YES if the class in question is the class you send or a subclass of that. Whereas isMemberOfClass: will only return YES if the class you are messaging is an instance of the class you are sending it
example: