I have a class:
@interface BasicDescription : NSObject
@property (strong,nonatomic) NSString *author;
@property (assign,nonatomic) NSInteger year;
@property (strong,nonatomic) NSString *owner;
And second class:
@interface AdvDescModel : BasicDescription
-(id)initWithBasicModel:(BasicDescription*)basicModel;
So my question is how to assign all properties when i’m create new object. Now i have
AdvDescModel *adv = [AdvDescModel alloc] initWithBasicModel:basic];
And then in initializer:
-(id)initWithBasicModel:(BasicDescription*)basicModel {
if(self = [super init]) {
[self setAllParams:basicModel];
}
return self;
}
-(void)setAllParams:(BasicDescription*)bModel {
[self setAuthor:bModel.author];
[self setYear:bModel.year];
[self setOwner:bModel.owner];
}
But there is no better way to do this? Now i have to watch all my properties and calling setter for every one of them.
The way you initialize your object is not bad, if it fullfil your requirements you can leave in this way … However take a look at the Builder Pattern that would be the best bet in these kind of situations.