Objective C — narrow instance variable types in subclasses?

后端 未结 4 623
无人共我
无人共我 2020-12-11 08:02

Is it possible to narrow the allowed type of an ivar in a subclass. Something like this:

@interface person: NSObject {
  NSArray *friendArray;
}

@interface         


        
4条回答
  •  一整个雨季
    2020-12-11 08:42

    @class doesn't make sense at all... it should be @interface. So the first error is purely syntactical.

    And no, you cannot change the type of an ivar. And that's for a good reason: Narrowing it down (as you do) can't work, because the parent class might rely on a different implementation. Widening it can't work as well (mainly for the analogous reason.

提交回复
热议问题