I am completely new to objective-c and I am currently in the learning process,
I have a parent class A which a property a,
I am trying to access the property in a subclass B,
When I access the property and assign a value like this
[self a:3];
it does complain No visible @interface for B declares selector a
but if I access it to read from it like
int something = [self a];
then it does not complain.
I understand the recommended way to access properties is using the . between object and property, but technically speaking it should work with message style call. but it’s not, so please advise me on this.
my code is like this
// Test class A
@interface A : NSObject
@property int a;
-(void) initMe;
@end
@implementation A
@synthesize a;
-(void) initMe
{
NSLog(@"I am in A");
}
@end
//-------------------------
@interface B : A
-(void) initEx;
@end
@implementation B
-(void) initEx
{
// This line gives a problem as I mentioned above
[self a:3];
NSLog(@"In child class B");
}
@end
///-----------------------
[self a:3];is the wrong syntax. If you want to call the setter method, it should be: