Reputation:
I was wondering if attributes were automatically set to nil
during an object's initialization or they have random values?
Upvotes: 1
Views: 518
Reputation: 28688
All instance variables are guaranteed to be initialized to nil or zero. This goes for non-object iVars as well, (int, BOOL, float).
Upvotes: 4
Reputation: 5205
If this question is indicative of Objective-C, I'd say that you should initialize all values of a variable when you declare them.
Explicitly initializing variables when they're declared gives you two benefits:
Upvotes: 1
Reputation: 6753
In Java, the data members of a class are set their default values. I.e string = null ,int =0.
Upvotes: -1