How does the .m file connect with main.m?


#1

I am looking at the structure of an application at a fairly granular level and while the .h file imports foundation and main.m imports foundation and .h, the .m file only imports from .h. How do the contents of the .m file get incorporated into main.m? I don’t see any import link there.

Thanks.


#2

Remember that the class is broken up into .h and .m simply for our human organizational needs. You import the .h so that the compiler can know what the class has in it, but you could skip the file all together and just put the @interface section in .m before the @implimentation.


#3

Also, the .m files are linked after compilation, not before, which is why you don’t see any inclusion of your additional .m files into main.m.

main.m is compiled into one binary file, your other .m files are compiled into separate binary files, and then they are assembled into the final build. Xcode takes care of all those details for you.


#4

Thank you both for the insights. Very helpful.