What does isa mean in objective-c? -
I want to know the meaning of the lines written below with an example. I am unable to understand what the lines really are Lines are from Google's objective-c coding guidelines.
Start
Do not start the variable 0 or zero in the init method; It is unnecessary.All memory for a new allocated object is initialized for 0 (excluding ISA), so do not dislodge the init method by starting the 0 or 0 variable again.
Under the hood, objective-object is basically C structs. Each has a field called isa
, which is an indicator of the class that is an example of an object (thus knowing the object and the object-c is the kind of runtime).
In relation to the initialization of the variable: In Objective-C, the example variable can be automatically generated by 0
(C types such as int
) or zero
(For Objectives-C objects) Apple's guidelines say that in your init
methods it is impossible to start those eBooks, so do not do so, for example, say You have one such class:
@interface MyClass: NSObject {int myInt; Double myDouble; MyOtherClass * MyObuse; } @end
Writing your init
method in such a way would be unnecessary, because those 0 or zeros < / Code> Anyway:
@implementation MyClass - (id) init {if ((self = [super init])) {myInt = 0; MyDouble = 0.0; MyObj = Zero; } Healthy return; } @end
You can do this instead:
@implementation MyClass - (id) init {return [super init]; } @end
Of course, if you want ivars to be started for values other than 0
or zero
You should still start them:
@implementation MyClass - (id) init {if ((self = [super init])) {myInit = 10; MyDouble = 100.0; MyObj = [[MyOtherClass alloc] init]; } Healthy return; } @end
Comments
Post a Comment