(Not So) Silly Objective-C inheritance problem when using property - GCC Bug?

后端 未结 4 1597
滥情空心
滥情空心 2020-12-05 15:40

Update - Many people are insisting I need to declare an iVar for the property. Some are saying not so, as I am using Modern Runtime (64 bit). I can confirm that I have bee

4条回答
  •  醉话见心
    2020-12-05 16:16

    I'm seeing error: 'testString' undeclared (first use in this function) when the @synthesize is just before the testing method. The error disappears if I move the @synthesize below the method implementation. This might be because the TestB class doesn't have a testProp string instance variable to use with the declared property. (In the Legacy (32-bit) runtime, you must declare instance variables to use for properties — in Modern runtime (64-bit Mac, iPhone) they can be inferred, so declaring them is optional.) Is it possible that you meant to name the property testString instead?


    EDIT: In GCC 4.2, it works if you change TestB.h to the following:

    #import "TestA.h"
    
    @interface TestB : TestA {
        NSString *testProp; // <-- Adding this fixes the errors
    }
    @property NSString *testProp;
    
    @end
    

    However, using the Clang-LLVM compiler, the code works unmodified. Perhaps this is a bug to file.

提交回复
热议问题