#importing class files

Apprentice
Posts: 13
Joined: 2008.09
Post: #1
Ive been spending some time attempting to learn Obj-C, at times a very frustrating experience. Currently I have been rereading "Learning objective-c on the mac".
one thing thats unclear to me is #importing class files. it appears that the class .m file ( implementation section ) is never #imported. I cannot figure out how the compiler recognizes this file and where it puts the source code.

lets say I have Class1.h and Class1.m files
most examples Ive found #import the Class1.h into Class1.m ( this makes sense) and also #imports the Class1.h into the main.m file ( why is Class1.h also #imported here? )

Ive googled for this and couldnt find an answer - I must be overlooking something simple.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #2
Basically, #import functions similar to #include -
it give's the compiler enough information to generate source code for the current source file. For example, dynamic memory for variables of type XXX will have enough space for data members. Thus, each implementation file is compiled into an object file.

The linker then takes these compiled object files built from the implementation files and assembles them into executable file.

There is no need to #import the .m files, but the linker is told the list of .obj files to use.

If you google some old school gcc documentation, you can see the linker step separate from the compile step.

Hope this helps...
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #3
Hey OptimisticMonkey do you attend the Phoenix Cocoahead meetings?

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2008.09
Post: #4
Thanks! I didnt realize that .m files were compiled separately then linked. A lot of Objective-C is not very intuitive to me. I will look up the compiling step in my books and see if this is detailed.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #5
kodex - Didn't know there was a Phoenix Cocoahead...where and when are the meetings?
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #6
OptimisticMonkey Wrote:kodex - Didn't know there was a Phoenix Cocoahead...where and when are the meetings?


http://groups.google.com/group/xcodephoenix?lnk=

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Post Reply