Copy header files into include folder with CocoaPods - ios

I developing a library and I have next use case. For instance, I have project A that has dependency on project B. I want to setup my pod in project B, so both project A and project B have access to my pod functions. So dependency chain will look like:
My Lib
|
B
|
A
Actual code will be compiled and available in runtime in project A almost automatically, but I can't compile it because project A does not see header files from my library. The header files places in Pods/MyLib/MyLib/CustomIdentifier directory (because s.header_dir = 'CustomIdentifier' to have access with import like: #import <CustomIdentifier/Header.h>).
I don't want to specify in project A direct path to header file (I do not want user have to do additional action to install my lib). I want CocoaPods to copy my header files or links to them into Products/../include folder so they will be available automatically.
How can I do it? Preferably with podspec file.
Thank you for you help!

Looks like it has to do with folder paths
Quoting from docs:
header_mappings_dir
A directory from where to preserve the folder structure for the
headers files. If not provided the headers files are flattened.
Examples:
spec.header_mappings_dir = 'src/include'
Helped me with a similar issue.
s.header_mappings_dir = 'armadillo-4.200.0/include/' #allows any folders in here to be avail from project. Namely the folder of headers, armadillo_bits
http://guides.cocoapods.org/syntax/podspec.html#header_mappings_dir

Related

How to create a framework from a C library with nested headers

I want to create a iOS framework for a popular C library.
My Current Setup:
This is what I'm doing:
Build the library for iOS and iPhone simulator architectures
Combine the two archive .a files into a single fat library using lipo
Use libtool -static -o to get the final library
By this stage I have a binary and a bunch of header files. In xcode:
Drop the binary (from step 3) and ensure its linked under: Target > General > Framework and Libraries, and Target > Build Phases > Link Binary with Libraries
I copy all the header files from the C library and place them under dir Dependencies/myClibrary/include/. The include dir contains a master header file myClibrary.h which includes a number of header files from ./abstract/*.h.
At top level of the xcode project dir, I also create a module.map file with content:
module MyWrapperFramework [system] {
header "Dependencies/myClibrary/include/myClibrary.h"
export *
}
Add all header files to xcode and for each header file, under Target Membership change value from project to public.
Build
Testing the framework in an App
I am able to build the framework, with settings as mentioned above. However, when I want to test it in a test Objective C app, I import the framework and call functions related to the myClibrary. On building the app, I get the error:
'myClibrary/abstract/headername.h' file not found
The above error originates from myClibrary's master header file myClibrary.
Most of the tutorial that I could find deals with C libraries having a single header file. How can I create a iOS framework from a C library that contains nested header files?
In case, nested header files are not the main issue here, what am i doing wrong?
A framework's headers get installed in the Headers directory inside the .framework. The compiler knows enough magic that when you say #import <myClibrary/myClibrary.h> that it will start the search for myClibrary.h inside that Headers directory.
As a result, the default public header build rules are to copy all public .h files (no matter their position in the source tree) into that Headers directory. That directory should be set as the $PUBLIC_HEADERS_FOLDER_PATH variable during building.
It seems as though you need to install headers into different directories. You could simply set the value of the Public Headers Folder Path in build settings to be a subdirectory, which will then install all public headers there. You could then have a custom Copy Files build phase to install just the single, overall header into the original headers directory.
Or, you could just add just the headers which go into the root as public headers, then have a custom Copy Files phase for all the rest, which copy them into a custom subdirectory. I think if you choose "Wrapper" as the destination, that is the root of the framework, so if the subpath is "Headers/abstract" that should work (though I have not tested myself). If you need to have multiple subdirectories, you would need a custom Copy Files build phase for each one.
Or, of course, have a custom build script to copy the headers more manually, if that's easier than multiple build phases (say one that copies all files in the include directory to $PUBLIC_HEADERS_FOLDER_PATH but preserving the structure, if there are a lot of subdirectories).

Cocoapod spec file creates extra folders

I created new cocoapod project by using pod lib create, changed folder name, edited spec file and updated example project.
In the screenshot you can see that the extra folders have been created. What is my mistake and how to correct it?
Thanks a lot...
Screenshot: https://cloud.githubusercontent.com/assets/7072397/12080819/b191e36c-b278-11e5-8bda-9569795d536b.png
You are not making any mistake, but .podspec file is meta data file for Pod.
A specification describes a version of Pod library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
You can get more detail about Pod Specification file from Cocoapods site.

how to include a file in your hosting app for a cocoapod File

I have a private cocoapod to share common models and controllers at our company. There is a config file that needs to be included because it
is referenced in the Cocoapod file. For example, if we have:
sample-proj/Pods/OurClasses/Classes/MyViewController.m
which has
#import "ABCConfig.h"
and ABCConfig is in sample-proj, how would I tell it to include it correctly? We have a project for which this works correctly and I thought
it would adding $(SRCROOT) in Search Paths -> User Header Search Paths but this doesn't seem to do it (although this could be some wierd Xcode artefact).
I can infer the problem as specifying a set of config to the libarary/framework. You should rethink of how you set a config and `import "ABCConfig.h" is right or not. There are couple of options,
Modify config file after you do pod install (this will be lost with next pod install),
use different config as submodule and import corresponding module when installing pods
Expose an API to feed in the configuration to library (best approach - flexible for user to tweak and give their configuration).

Integrating UrbanAirShip - Header search paths with relative path

I'm trying to integrate UrbanAirShip in my application following these steps .
This is what i've done:
1) I've Unziped the framework in the Project folder so that I have the Airship folder at the same level of other file of my project.
2) I've added the path ./Airship/** to my Header search Paths.
I've also tried with ../Airship/** but it doesn't work.
3) I try to include the right headers
#import "UAirship.h"
#import "UAConfig.h"
#import "UAPush.h"
But xcode complains... saying 'UAirship.h' file not found.
What I'm doing wrong? Have I to include the files into the project?
Neither ./ or ../ worked for me in the Header Search Paths. I ended up using this:
$(PROJECT_DIR)/Airship
Airship folder is in same level as the project.
You mistyped the path to add in the Header Search Paths (forgot one ".") :
./Airship/**
Should be :
../Airship/**
Did you do the following step:
Link against the static library.
Add the libUAirship.a file to the “Link Binary With Libraries” section in the Build Phases tab for your target.
May not be applicable all of two years later, but I encountered a very similar problem today and solved it by using the CocoaPods version of the framework found here:
https://cocoapods.org/pods/UrbanAirship-iOS-SDK
After running pod install, I added the following paths to my Header Search Paths under target project > build settings:
It seemed redundant to me to add both paths, but without the subfolders at /** the AirshipLib.h file wasn't able to locate its dependancies, and without the main folder my Bridging-Header.h file wasn't able to locate AirshipLib.h
Luckily enough I'm using some old Objective-C files from our codebase and incorporating them into a new Swift app, so I already had a Bridging-Header.h file, but if you needed to create one you can find instructions here:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Finally, I added the following to my Bridging-Header.h file:
#import "AirshipLib.h"
No issues on build and everything from the framework can be easily referenced directly in my files.

How to tell Xcode how to include a library specified with angle brackets?

I often see open source code importing third-party libraries in Xcode / Objective-C implementation files like this:
#import <ThirdPartyLibrary/utilities.h>
but when I drag & drop the file structure and files of such a library in my project, all these imports are corrupted and Xcode does not know where the files are.
I end up hand-modifying every import to look like:
#import "utilities.h"
And include appears it is relative to the current physical folder on the file system. When a library split its files in folders on file system and I drag-drop it in Xcode, Xcode creates groups for the folders. But for import, I have to specify the folder name. Problem is when I am in a folder, for example:
http/httpTools.h
Then when httpTools.h wants to import utilities.h from the root, I have to change
#import <ThirdPartyLibrary/utilities.h>
to
#import "../utilities.h"
which is a chore. After doing this for 5 hours I thought damn, there must be a better way. Can someone explain what is the secret to teaching Xcode a new framework location that can be imported with angle brackets? The framework btw is source code. Not compiled. Just the naked code.
Specify the include path using the compiler flag -I, or the Xcode build settings alias HEADER_SEARCH_PATHS. Of course, you can use build variables when doing so.
Just stumbled upon the same issue, there are two types of search paths in Xcode:
Header Search Paths
User Header Search Paths
If you add your own include folders into Header Search Paths, you can use angled brackets.

Resources