初始设置涵盖所有选项

时间:2022-02-17 22:40:08

I want to call initialProperties to cover all options of it instance

我想调用initialProperties来覆盖它实例的所有选项

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initialProperties];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initialProperties];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initialProperties];
    }
    return self;
}  

This my code.
question1: am i right?
question2: what the diffence between these?

这是我的代码。问题1:我是对的吗?问题2:这些之间的差异是什么?

1 个解决方案

#1


0  

I think you make it.
In UIView init is exactly equal to [super initWithFrame:CGRectZero]
initWithCoder is called when use xib or storyboard
And initWithFrame as we all know

我想你做到了。在UIView中,init完全等于[super initWithFrame:CGRectZero]在使用xib或storyboard和initWithFrame时调用initWithCoder我们都知道

#1


0  

I think you make it.
In UIView init is exactly equal to [super initWithFrame:CGRectZero]
initWithCoder is called when use xib or storyboard
And initWithFrame as we all know

我想你做到了。在UIView中,init完全等于[super initWithFrame:CGRectZero]在使用xib或storyboard和initWithFrame时调用initWithCoder我们都知道