Just got tripped up here. Was doing some runtime type checking… if an instance is this class, do this, if it’s this class, do this. A bit hacky, may clean it up later, but anyway…
I was using something like:
[c]if([[myObject className] isEqualToString:@“SomeClass”]) {…}[/c]
And it was working just fine.
In the simulator.
Then I tried it on the device. Suddenly, I’m getting crashes and with some investigation, find that “NSObject may not respond to className.” But I saw it in the docs! Honest! Let me look it up again… Wait, it’s not there anymore. Search a bit more… oh, yeah, there it is. WTF?
Turns out that OS X has a bit different version of NSObject than the iPhone does. Here’s the reference for the iPhone version:
And here’s the OS X version:
You’ll see in the OS X version, there’s a “scripting” section that is missing in the iPhone version. And that’s where className lives.
“But wait,” you say, “You said it was working fine at one point.” Yes I did. In the simulator. Apparently, the simulator uses the OS X version, so you can merrily program away your iPhone app with APIs that don’t exist on the iPhone. And then it all blows up when you install it. Fantastic. Anyway, little heads up there. In case you run into that yourself.