“Variable Undeclared” error when compiling to iOS Device, but not for Simulator

后端 未结 10 1348
时光取名叫无心
时光取名叫无心 2020-12-31 10:15

I have an custom UIVIewController that is the base class for other controllers and has an instance of a custom UIView variable that is accessed by inherited the classes.

10条回答
  •  难免孤独
    2020-12-31 11:10

    It is possible that when you compile for target and for simulation the data members are either protected or private. Probably for target are private by default and this seems to cause the problem. Try out playing with the @private and @protected keywords.

    However, I strongly suggest that you use properties even between your super/sub-classes. Having a complex structure is a bit hard to debug. Setting up a property will transfer the access to the data through the getter/setter methods (a breakpoint on @synthesize also works) and you will be able to see in the call stack who is accessing what.

    Especially, the syntax @synthesize propertyName = prefixDataNameSufix; allows you to easily adjust your class interface style without having to modify your coding habits.

提交回复
热议问题