我有下一个代码:
GenericClass.h:
@interface GenericClass : NSObject
@property (nonatomic) char tile_inicial;
@property (strong, nonatomic) NSString *color;
GenericClass.m
@implementation GenericClass
-(id)init
{
self = [super init];
return self;
}
- (id)initTodo:(char) tile
{
_tile_inicial = tile;
return self;
}
@end
Animals.h:
#import "GenericClass.h"
@interface Animals : GenericClass
@property (nonatomic) bool fly;
@property (strong, nonatomic) NSString *sound;
@end
@interface Cow : Animals
@property (nonatomic) bool daLeche;
@end
Animals.m
#import "Animals.h"
@implementation Animals
-(id)init
{
self = [super init];
return self;
}
- (id)initAnimal:(bool)fly :(NSString *) sound :(char) tile
{
_fly = fly;
_sound = sound;
self = [super initTodo: tile];
return self;
}
@end
@implementation Cow
-(id)init
{
self = [super initAnimal: false :@"Muu Muu": 'v'];
if (self) {
_daLeche = true;
}
return self;
}
@end
问题是我想直接从Cow构造函数调用任何属性(例如颜色或声音)并初始化它。 但是,如果我尝试在不调用父构造函数的情况下执行它,则返回:“找不到属性” 有什么想法吗?
提前致谢