How would it be more correct to initialize the properties of objects in the init method — to access the property directly through an underscore or through self ?

The only danger in accessing self is that I only see that there is no if (self) check, and the need to use _obj = @ "name"; only if by some miracle the property needs to be initialized before the object itself

example:

- (instancetype)init { self = [super init]; if (self) { self.nameString = @"name"; _nameString = @"name"; } return self; } 

    1 answer 1

    Apple recommends to always use underscores in intits, arguing that:

    It is not clear that it has been completely initialized. It can be very well override the behavior.

    Transfer:

    Of the initialization methods, you should always refer to the instance variables directly, because at the time when the property is set, other parts of the object may not be fully initialized yet. Even if you do not provide custom access methods, or are confident that there are no side effects in your class, subclasses may create this behavior in the future.

    Taken from the documentation .

    At the same time, I want to add from myself that I always do through self, there have been no problems so far.

    • Immediately everything became clear, thanks - Alexey Alybin