Cocoa Objective-C header file question

Posted:
in Genius Bar edited January 2014
So I got Aaron Hillegass' new Cocoa Programming book, and I'm working through an example. At one point he shows adding a method to the implementation file, but not to the header file. Here is the method:

Code:




- (void)awakeFromNib

{

// stuff to do

}









So I went to the header file and added it in with the other method declarations. It runs fine without that method declared in the header file, and also with it added. I assume he just overlooked telling us to add it, or assumed that we'd know to do it on our own. Do you not need to add methods to the header file that don't return a value? I wouldn't imagine that would be the case. I've done some Java before, but the C header and implementation files are kinda new.



Any help is appreciated.



Thanks

Comments

  • Reply 1 of 4
    thuh freakthuh freak Posts: 2,664member
    well, actually, i'm pretty sure (about 60%) that you don't need any method declarations in the header file (and i'm 99% sure that its completely independant of return types [or lack], and parameters). You put them in for clarity, but not as a requirement of the language. The compiler will warn you if a class (plus all its parents) doesn't have a method, and you try to use it. but thanks to late-binding of objects (pretty sure i'm using the wrong terminology there, hopefully you get the gist), the language can't guarantee that the typed-object does NOT have a method. and, as it turns out, with that particular method, its from one of the parents (i think NSObject).



    at run time, when you call a message on an object, if the object doesn't really respond to the message, you get a runtime error (which, i'm 50% sure means that the return value of the whole expression is NULL, or some kind of popup happens, or soemthing is spit on the error log [maybe all three, or somethign else similar]). haven't done objective-c in a few months, so i'm a little out of practice.



    and repeating the declaration in a subclass, as well as the parent, doesn't hurt anything. even if you dont re-implement the method in the subclass, it will only reiterate to the compiler that the method exists somewhere in the subclass' hierarchy.
  • Reply 2 of 4
    airslufairsluf Posts: 1,861member
    Kickaha and Amorph couldn't moderate themselves out of a paper bag. Abdicate responsibility and succumb to idiocy. Two years of letting a member make personal attacks against others, then stepping aside when someone won't put up with it. Not only that but go ahead and shut down my posting priviledges but not the one making the attacks. Not even the common decency to abide by their warning (afer three days of absorbing personal attacks with no mods in sight), just shut my posting down and then say it might happen later if a certian line is crossed. Bullshit flag is flying, I won't abide by lying and coddling of liars who go off-site, create accounts differing in a single letter from my handle with the express purpose to decieve and then claim here that I did it. Everyone be warned, kim kap sol is a lying, deceitful poster.



    Now I guess they should have banned me rather than just shut off posting priviledges, because kickaha and Amorph definitely aren't going to like being called to task when they thought they had it all ignored *cough* *cough* I mean under control. Just a couple o' tools.



    Don't worry, as soon as my work resetting my posts is done I'll disappear forever.
  • Reply 3 of 4
    Thanks guys. What both of you say makes sense. AirSluf, I had just thought to myself that awakeFromNib was already imported from the frameworks. You confirmed it though.



    Thanks, question answered.
  • Reply 4 of 4
    airslufairsluf Posts: 1,861member
    Kickaha and Amorph couldn't moderate themselves out of a paper bag. Abdicate responsibility and succumb to idiocy. Two years of letting a member make personal attacks against others, then stepping aside when someone won't put up with it. Not only that but go ahead and shut down my posting priviledges but not the one making the attacks. Not even the common decency to abide by their warning (afer three days of absorbing personal attacks with no mods in sight), just shut my posting down and then say it might happen later if a certian line is crossed. Bullshit flag is flying, I won't abide by lying and coddling of liars who go off-site, create accounts differing in a single letter from my handle with the express purpose to decieve and then claim here that I did it. Everyone be warned, kim kap sol is a lying, deceitful poster.



    Now I guess they should have banned me rather than just shut off posting priviledges, because kickaha and Amorph definitely aren't going to like being called to task when they thought they had it all ignored *cough* *cough* I mean under control. Just a couple o' tools.



    Don't worry, as soon as my work resetting my posts is done I'll disappear forever.
Sign In or Register to comment.