Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

How to #import <Lib/Header.h> and avoid to fill HEADER_SEARCH_PATH

--> Updated methodology to create a library that install the headers itself, so they can be imported vi #import <Lib/Header.h> and we won't need to add any HEADER_SEARCH_PATH to your app project
  • Loading branch information...
commit ac109e671633cacb55ac778549baed9a579874ad 1 parent c7fc921
@AliSoftware authored
View
2  .gitattributes
@@ -1,2 +0,0 @@
-*.pbxproj -crlf -diff -merge
-
View
16 .gitignore
@@ -1,11 +1,17 @@
# xcode noise
-build/
-*~.nib/
-*.pbxuser
-*.perspective
-*.perspectivev3
+*/build
+*.pbxuser
+!default.pbxuser
*.mode1v3
+!default.mode1v3
*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+profile
+*.moved-aside
+
# old school
.svn
View
4 LibraryWithRsrc/Demo/Demo2App/CHViewController/CHViewController.m
@@ -7,8 +7,8 @@
//
#import "CHViewController.h"
-#import "Demo2Lib.h"
-#import "CHLibViewController.h"
+#import "Demo2Lib/Demo2Lib.h"
+#import "Demo2Lib/CHLibViewController.h"
@interface CHViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
View
4 LibraryWithRsrc/Demo/Demo2App/Demo2App.xcodeproj/project.pbxproj
@@ -300,9 +300,7 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Supporting Files/Demo2App-Prefix.pch";
- HEADER_SEARCH_PATHS = ../Demo2Lib/Classes;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Demo2App-Info.plist";
- LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
@@ -314,9 +312,7 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Supporting Files/Demo2App-Prefix.pch";
- HEADER_SEARCH_PATHS = ../Demo2Lib/Classes;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Demo2App-Info.plist";
- LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
View
8 LibraryWithRsrc/Demo/Demo2Lib/Demo2Lib.xcodeproj/project.pbxproj
@@ -14,6 +14,9 @@
0967A73616A324F200886818 /* CHLibViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0967A71916A3206400886818 /* CHLibViewController.xib */; };
0967A73716A324F600886818 /* CocoaHeads.png in Resources */ = {isa = PBXBuildFile; fileRef = 0967A71C16A320CA00886818 /* CocoaHeads.png */; };
0967A73816A324F900886818 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0967A6F416A31B9D00886818 /* Localizable.strings */; };
+ 09804E5C16A8DCD100ADC660 /* UIImage+Bundle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 09A22DE716A61CCD0056B9A8 /* UIImage+Bundle.h */; };
+ 09804E5D16A8DCD300ADC660 /* Demo2Lib.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0967A6D316A3193700886818 /* Demo2Lib.h */; };
+ 09804E5E16A8DCD500ADC660 /* CHLibViewController.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0967A71716A3206400886818 /* CHLibViewController.h */; };
09A22DE516A61B460056B9A8 /* CocoaHeads@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 09A22DE416A61B460056B9A8 /* CocoaHeads@2x.png */; };
09A22DEA16A61CCD0056B9A8 /* UIImage+Bundle.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A22DE816A61CCD0056B9A8 /* UIImage+Bundle.m */; };
/* End PBXBuildFile section */
@@ -35,6 +38,9 @@
dstPath = "include/${PRODUCT_NAME}";
dstSubfolderSpec = 16;
files = (
+ 09804E5C16A8DCD100ADC660 /* UIImage+Bundle.h in CopyFiles */,
+ 09804E5D16A8DCD300ADC660 /* Demo2Lib.h in CopyFiles */,
+ 09804E5E16A8DCD500ADC660 /* CHLibViewController.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -323,7 +329,6 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Supporting Files/Demo2Lib-Prefix.pch";
- OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
@@ -334,7 +339,6 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Supporting Files/Demo2Lib-Prefix.pch";
- OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
View
46 LibraryWithRsrc/README.md
@@ -1,3 +1,12 @@
+* [LibraryWithRsrc](#librarywithrsrc)
+* [Example usages](#example-usages)
+* [How to generate a clean an reusable library](#how-to-generate-a-clean-an-reusable-library)
+ * [Create a library project](#create-a-library-project)
+ * [Integrate the library in your application project](#integrate-the-library-in-your-application-project)
+* [How to generate a valid resource bundle](#how-to-generate-a-valid-resource-bundle)
+
+---
+
## LibraryWithRsrc
This is an example of how to create a Xcode projet that generate **both** a static library **and** a _resource bundle_.
@@ -38,6 +47,43 @@ All you will need to do to use them in your applications then is to link the app
of course, and add the resource bundle that your project generated with the static library (thanks to a second, dedicated target)
to the resources of your app.
+## How to generate a clean an reusable library
+
+> **Note**: this is not exactly the process I presented in my CocoaHeads presentation #12 in Rennes (17 Jan 2013) since I found this much better solution a bit later.
+> Contrary to what I told in my CocoaHeads presentation:
+
+> * There will be no need to fill the `HEADER_SEARCH_PATH` Build Setting in your application project
+> * We will use the "Copy Files" phase (and not the "Copy Headers" phase) as explained by Apple
+> [here](http://developer.apple.com/library/ios/technotes/iOSStaticLibraries/iOSStaticLibraries.pdf) -- so we won't have to use a workaround involving the Installation Path of the lib to make it work in "Archive" mode.
+
+---
+
+### Create a library project
+
+* Create a **new project of type "Static Library"**, and add this project to your workspace
+ * If you don't have a workspace already, simply create a new workspace and add both your application project and this library project to it
+* Add your code (`.h` and `.m` files) to this project
+* Go in the **"Build Phase"** tab of your library project. You should have a **"Copy Files" phase** already provided by the project template. If this is not the case:
+ * Click on the "Add Phase" button at the bottom of this screen and choose "Copy Files"
+ * Choose "Products Directory" in the "Destination" dropdown menu
+ * Type `include/${PRODUCT_NAME}` in the "Subpath" field
+* **Add all your public headers to this phase** (by drag & dropping the `.h` files from the Project Navigator, or with the "+" button)
+ * You should only add public headers here: if you have a header that is not intended to be imported by applications that
+ use your library, don't add it there. This way the application won't be able to `#import` your private headers that declare any private API.
+ * Don't forget to add headers to this phase each time you create a new `.h` file (that is intended to be public) in your library project!
+* **Build the library project for "iOS Device"** (not the simulator) once, to check that it builds correctly and to make Xcode know where it will be generated
+
+### Integrate the library in your application project
+
+* Select your application project in your workspace, and go to the **"Build Phases"** tab
+* Open the **"Link Binary With Libraries"** section and add your static library (`libSomething.a`) there (using the "+" button)
+* In your Project Navigator on the left of Xcode, select the new file reference (`libSomething.a`) that has been added to your application's xcodeproj
+ and in the File Inspector on the right, select **"Relative to Build Products"** in the "Location" dropdown.
+ _(This way you will ensure Xcode will detect implicit dependencies between your app and the library)_
+* In the **"Build Settings"** of your application's project, add the `-ObjC` flag to the `Other Linker Flags` setting
+
+You can now **use `#import "YourLib/Header.h"` or `#import <YourLib/Header.h>` in your application's code** and start calling your library methods.
+
## How to generate a valid resource bundle
Since Xcode 4 does not provide a template to generate a Resource Bundle for iOS, you will use the template for OSX bundles
Please sign in to comment.
Something went wrong with that request. Please try again.