开发者

How to check if an object was initialized? Objective-C

开发者 https://www.devze.com 2023-01-31 10:26 出处:网络
I\'m wondering if there isa way to check wether a variable that has been declared has been assigned or initiali开发者_如何学JAVAzed or not in 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){ };
0

精彩评论

暂无评论...
验证码 换一张
取 消