开发者

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, an开发者_如何学运维d 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.


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];

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜