Search code examples
iosobjective-cxcodesubproject

Referring to an .h class of a subproject


the Dropbox iOS SDK has its own Framework bundle but in order to customize it easily I ve chosen to include its Xcode project as a subproject. How should i refer to its .h classes? I ve added the .xcodeproj from the "Add files" button and I ve added in the Header Search Path the following value:

$(PROJECT_DIR)

The subproject looks to be at the same level with the main project.

Shouldn't the importing itself link the dependencies?

(I m really frustrated by the import system in Xcode)


Solution

  • Your basic approach seems sound (and is pretty close to how I handle lots of vendor projects). Since you've added $(PROJECT_DIR) to your header search path, and assuming that the framework is in a directory named "Dropbox", then you can refer to the packages a couple of ways:

    #import <Dropbox/Header.h>
    #import "Dropbox/Header.h"
    

    I prefer to think of the sub-projects as "system-like" and so tend to use angle-brackets, reserving double-quotes for internal code. But either approach is really fine.

    Shouldn't the importing itself link the dependencies?

    No. You still need to link the dependencies. #import does just exactly one thing: inserts the requested file into the current file. That's all it does. It is identical to you taking the referenced file and copy/pasting it into your code (that's basically how it's implemented in the pre-processor). That this is used for "header" files is a matter of convention. It has nothing to do with how the compiler works. You technically could import a .m file that included a method in it as a way to do code reuse. (I've seen that done in projects I've worked on. Please don't do this....)

    When dealing with ObjC modules, it's a little different (using @import rather than #import). But if you're just importing headers as you seem to be, think of it as "stick this other file right here, exactly as written."