I'm trying to access private properties on a inherited class. Is that possible with that naming convention apple gave me?
Header:
#import <Foundation/Foundation.h>
@interface FooBar : NSObject
-(void)doSomeThingWithThisNumber:(NSInteger)aNumber;
@end
Implementation:
#import "FooBar.h"
@interface FooBar()
@property NSInteger myPrivateFoo;
@end
@implementation FooBar
@synthesize myPrivateFoo = _myPrivateFoo;
-(void)doSomeThingWithThisNumber:(NSInteger)aNumber
{
_myPrivateFoo = aNumber;
}
@end
if i inherit this class to a new one i can't access _myPrivateFoo
. Is there another way to do it instead of the declaration in the header file?
In the implementation of the subclass, simply put the private category declaration before your main @interface. This will prevent compilation errors because the compiler will know that the property exists. This is what I mean by "the private category declaration":
@interface FooBar()
@property NSInteger myPrivateFoo;
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With