I have a view, and I want to remove it in a particular situation.
if (self.superview) {
[self removeFromSuperview]; // breakpoint point here
}
I lldb
it :
(lldb) po self.superview
0x0000000000000000
How to judge the superview
equals to 0x0000000000000000
?
It is safe to send
removeFromSuperview
to a view even if the view isn't in a superview. If the view isn't in a superview, the message will have no effect. So testingself.superview
is not necessary.When
self.superview
prints as0x0000000000000000
, that means it isnil
, which meansself
is not in a superview.