ios - Why do devices previous to iPhone 5S and iPad Air don't crash when casting a null variable? -
i abstracted code here, since original massive:
-(void)something { // @ point, self.parent not null [self boom]; someclass *variable = (someclass*)self.parent; [variable somemethod]; } -(void)boom { self.parent = nil; }
surely, if call something
, crash, because self.parent
nullified, , attempt cast , call method on it.
so thing is, never crashed me. mean, several months, piece of code has been intact, , app never crashed.
now crashing 2 specific configurations
- iphone 5s, latest ios
- ipad air, latest ios
all other previous devices, latest ios too, didn't crash.
although above snippet not code, i'm pretty sure reflects happening.
how possible? missing here?
i don't doubt you're getting crash in real project, when factored out problem post here (a admirable practice, way, wish more people it), think factored out real source of crash.
messaging nil fine. casting happens @ compile time, , casting variable might nil @ runtime fine.
casting object bar when it's foo, invoking bar
method on cause nsinvalidargumentexception (unrecognized selector).
but that's not happening in op code. it's fine variable
nil instance of someclass
. no possible method invocation on cause crash.
Comments
Post a Comment