iphone - testing if an object exists
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-04-07T16:37:54Z
Indexed on
2010/04/07
16:43 UTC
Read the original article
Hit count: 482
I have several apps in my app that can become nil at some point and I have methods that in theory are used to put these objects to nil.
But, if I try to put to nil an object that does not exist, the app will crash.
for example...
[object1 release];
object1 = nil;
//... and after that
[object removeFromSuperview]; // this will crash
Then I thought, why not testing to see if the object exists before removing...
if (object1 != nil)
[object removeFromSuperview];
// this will crash too, because object1 cannot be tested for nil because it does not exist
How can I check if the object exists before testing if it is nil? something as
if (object exists( {
if(object != nil))
[object removeFromSuperview)
}
is this possible?
© Stack Overflow or respective owner