Objective-C: Compiler error when overriding a superclass getter and trying to access ivar

前端 未结 2 1509
旧时难觅i
旧时难觅i 2020-12-15 21:32

I\'m working on building an iOS 6 app.

I have a class TDBeam which inherits from superclass TDWeapon.

The superclass

2条回答
  •  轮回少年
    2020-12-15 22:19

    Synthesized ivars are not visible to subclasses, whether they are explicitly or automatically created: What is the visibility of @synthesized instance variables? Since they are effectively declared in the implementation file, their declaration isn't included in the "translation unit" that includes the subclass.

    If you really want to access that ivar directly, you'll have to explicitly declare it (in its default "protected" form) somewhere that the subclass can see it, such as a class extension of the superclass in a private header.

提交回复
热议问题