A few questions about overriding the init function

As a beginner of Objective-C, I am very confused about the init function and how and when to override it. So here are a few questions:

  • It seems to work fine when the init function is not overridden, so is that just good practice? If so, is it a very bad practice not to do this?
  • Suppose I redefine a function because I need to assign a default value to a variable. Should I allocate and initialize all other ivars, including IBOutlets?

Note that I know the syntax:

if ((self = [super init]))
{
    _foo = [[Bar alloc] init];
}
return self;
+3
source share
3 answers

Per "Initialization" :

, . , Cocoa . , . , . , . NSObject init , , .

, , , . ? .

NIB, -init . -initWithCoder: -initWithFrame: . NIB -awakeFromNib , NIB, . -initWithCoder:/-initWithFrame:, NIB. , , -awakeFromNib, , .

. " " , " " , " " , , Objective-C.

+5

-init ( ), .

( ) IBOutlets. Objective-C , IBOutlets, 0 (nil).

+4

... , ... IBOutlets ... , ....

0

All Articles