How to check if an object was initialized? Objective-C
I'm wondering if there is a way to check wether a variable that has been declared has been assigned or initiali开发者_如何学JAVAzed or not in Objective C..
thank you
All instances variables are set to 0 (or nil for objects) in the alloc method, see The Objective-C Programming Language.
This means you can check the variable with
if (!var) {...}
Be aware though that there is no way to differentiate between the state after initialization or just being set to 0.
Check if the object is 'nil':
if(object == nil){ };
精彩评论