-
Having It All With Xcode 4 Static Libraries
It’s been a long, annoying road to getting a usability balance with libraries in Xcode 4. Well, strike that. iOS static libraries have always been a little hellish experience-wise, whether it was your app crashing if that library had categories or the compiler not being able to find headers.
In Xcode 4, we got another obnoxious facet to this issue: auto completion, or, in Apple Magic™ terms, Code Sense. Long story short, Code Sense does not like external headers. It really doesn’t. Sometimes it just won’t index those external headers, making the experience for using, say, BlocksKit incredibly annoying. In working on PSFoundation, I ran into a much bigger issue where Xcode decides it just won’t highlight your code at all.
As most can guess, when things are a crapshoot like this, actually being able to compile and use your code was the primary issue over getting autocomplete to work. After weeks of investigation and toying around, I feel like I’ve worked things out.
The most common way to get headers working (without autocompletion) is to have the headers install to a named folder instead of /usr/local/include, so, properly:
/Users/zwaldowski/Library/Developer/Xcode/DerivedData/Filemator-/Build/Products/Debug-iphonesimulator/PSFoundation
A good way to get headers working (with autocompletion, but not always compiling properly) is to jump out of the proper Xcode scheme, e.g., Build/Products/PSFoundation over Build/Products/Debug-iphoneos/PSFoundation. Three20 does something like this, and I’ve followed them: in your static library target, set both “Private Headers Folder Path” and “Public Headers Folder Path” to “/../$(PRODUCT_NAME)/$(PRODUCT_NAME)”. Now, instruct your users to set their set their header search path to “$(BUILT_PRODUCTS_DIR)/../—project name—”. From then on, they use #import “—project name—/—main header—.h”, like #import “PSFoundation/PSFoundation.h”.
Their code will light up like a Christmas tree, things will autocomplete, and it will build.
Today, things are a little bit better with CocoaPods and fake frameworks. The former uses a method like this one, while the latter skirts Xcode’s wonky handling of static libraries entirely.
-
-
zwaldowski posted this
-