I’m new with Objective C and am not an uber programmer anyway but one thing I find odd is that it won’t throw errors sometimes when objects are declared not initialized.
I just ran into this again – I had some setup stuff to be done in so I put it in an init function – but the class is a UIViewController that is wired up in the storyboard. So init was never called – and that’s my error – (lots of NSObject derived classes in the project and I rushing and just tossed that in to test some things).
But my methods that were making calls to the instance that was supposed to have been set up in int didn’t throw errors – it just that the values I was expecting were nil.
Isn’t that sort of odd that that sort of stuff would fail silently?
You’ve got two separate issues here, both quite common for beginners.
Your
initwas never called because it’s the wrong method entirely. It’s not the designated initializer for a view controller, and in any case a view controller from a nib or storyboard getsinitWithCoder:. So it’s up to you to have a sense of what method will be called and when.Messages to nil return nil with no error. This is a deeply entrenched feature of Objective-C and isn’t going to change. There is often quasi-religious debate about it, and there are some clever ways around it, but that’s neither here nor there really. Basically it’s up to you to use lots of NSLog and lots of nil-checking (NSAssert is a great thing to use for this), especially during early stages.