ma11hew28
ma11hew28

Reputation: 126367

Objective-C: Cast super instance variable in subclass?

In Objective-C, in the definition of a subclass (perhaps in the interface file), is it possible to cast an instance variable (ivar) that's inherited from the super class?

I want to do this because I've defined the superclass's ivar as NSObject *session, and I want to cast the subclasse's ivar to Facebook *session, so that I don't have to cast it every time I'm sending it a message that Facebook instances respond to but NSObject instances don't.

Upvotes: 0

Views: 854

Answers (1)

Felipe Sabino
Felipe Sabino

Reputation: 18215

There is no way to change the type of a superclass interface variable, one thing you could do is to add a getter method, such as

- (Facebook *) getSession {

   return (Facebook *)[self session];

}

Upvotes: 2

Related Questions