I am recently developing an iphone app and I feel using inheritance makes the structure more sense and elegant. However, I am struggling with how does inheritance work in objc. The inheritance convention in Java does not seem work in here.
Circumstances:
It might be a bit complex but this looks the best way to describe the situation. Let's say I have 2 classes, A and B. And they look like the following:
// Class A
@interface A: B
@end
@implementation A
- (id)init{
self = [super init];
if(self){
}
return self;
}
@end
// Class B
@interface B: NSObject
@property A *littleA;
- (void)doSomething;
- (void)blabla;
@end
@implementation B
- (id) init {
self = [super init];
if(self) {
_littlea = [[A alloc] init]; // error: No known class method for selector 'alloc'
}
return self;
}
- (void)doSomething{
NSLog(@"something");
}
- (void)blabla{
[littleA doSomething]; // error: No visible @interface for 'A' declares the selector 'doSomething:'
}
@end
And outside of these classes, there is a class C. In class B, I passed 'littleA' to Class C's method. In that method, I did:
[littleA isEqual:NULL];// error: No visible @interface for 'A' declares the selector
I am utterly confused by these error messages.. Is this what the inheritance suppose to do? In Java, A extends B, B extends C, then I can call from A: a.b's method or a.c's method.
What did I do wrong? Anybody could explain the three error messages would be a great help!