0

In my objective c code, I try to set the super class property by

super.aProperty = something;

But I get this error "Property 'aProperty' not found on object of type 'MySuperClass'.

In my MySuperClass.m, I have

@interface MySuperClass ()

@property (strong, nonatomic) SomeProperty *aProperty;

@end

Can you please tell me why 'super.aProperty = something' is not working?

Thank you.

Update:

I tried move this line "@property (strong, nonatomic) SomeProperty *aProperty;" to .h.

But I get error saying 'Unknown type name 'SomeProperty' did you mean'SomeOtherProperty'? I have #include SomeProperty.h in my .h file.

michael
  • 106,540
  • 116
  • 246
  • 346

2 Answers2

2

Because it is not visible by compiler when compiling the subclass. You had the property in .m file instead of .h file which means it is a private property that is only visible in the same .m file.

If you want a public property, you need to put it in .h file and include the file when you need to access the property.

And most of the time, you can call it like self.aProperty = something; unless you have override it and don't want to call the implementation in child class (to avoid infinite recursion)

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
  • To add, it's also important to note that the property is defined in a Category, not a class definition. The syntax `@interface MySuperClass ()` is commonly used as a private Category to add functionality that is only needed in that specific class. In other words, the property doesn't really belong to the super class in the current definition. – Brandon Buck Dec 04 '14 at 05:18
  • 3
    @BrandonBuck It is actually called extension for unnamed category. – Bryan Chen Dec 04 '14 at 05:20
0

hope this will help you

you declare the variable inside the class extension(https://stackoverflow.com/a/24568948/3767017) and inside the class extension the variable can be only access privately.if you need to access that variable in other class you have to make it as a public or protected.

@interface yourClass : parentClass {
  SomeProperty *aProperty; // protected by default

  @protected
   SomeProperty *aProperty; 
 }

@property (strong, nonatomic) SomeProperty *aProperty;//public
Community
  • 1
  • 1
Anurag Bhakuni
  • 2,379
  • 26
  • 32