1

When I add a framework to a project, using Cocoapods or manually, they contain only header files. From Xcode, using "Jump to definition" there is no definition (that means that there are no .m files).

When a function in a library is called, how does the compiler get its implementation if the .m file is not in the project?

jscs
  • 62,161
  • 12
  • 145
  • 186
Ne AS
  • 1,300
  • 2
  • 20
  • 54
  • Compiler doesn't get implementation. It's already implemented in framework binary. Linker will link method calls in your code with implementation in framework. – Cy-4AH Oct 26 '17 at 14:17

1 Answers1

3

To put it in a somewhat simplistic way, building an executable usually goes through at least these two stages:

  • compiling, which turns source code into binary code;
  • linking, which "glues" chunks of binary code into an executable.

Frameworks may include implementations in binary form, already compiled. These are then linked with your compiled sources. The compiler does not touch them in any way, and only needs the .h files that describe them. It's the linker's job to stitch them together with your code.

If you'd like to know more on the subject, the answers to the following questions contain more detailed information:

Matusalem Marques
  • 2,229
  • 2
  • 16
  • 27
  • +1 Good, simple answer. You might want to clarify that it's the debug versions of the frameworks which are "linked" to the sources with debugging information, including the (location of) the source files. – greymouser Oct 26 '17 at 14:17