timpone
timpone

Reputation: 19969

possible to have a CocoaPods have a search path that includes the main app

This is my first time writing my own Cocoapod so this might be a really simple quedstion but ....

I am trying to use Cocoapods to distribute common code for a series of apps used within our company (the CocoaPod is called CommonHex with a prefix of HEX so HEXItem.h/m). However, we have a config file specific to each app called HOSTConfig.h/m. Is there any way to access this HOSTConfig.h/m from within our CommonHex pod?

It would seem like I should bOe able to have for example a config file which will have it's own values but would pull in for HOSTConfig.h/m if it exists? And would probably have to extend the search path or something.

So I have like:

MainApp
\-MainApp
   \-HOSTConfig.h/m

CommonHex
\-Classes
   \-HEXItem.h/m
   \-HEXItemViewController.h/m  

I would like this to be able to access HOSTConfig.h/m perhaps via another class where if HOSTConfig.h/m exists in the hosting app, it uses those values else it uses values in our CocoaPod

edit #1

so in CommonHex.podspec, I have the following but this doesn't seem to work:

  s.source_files  = "Classes", "Classes/**/*.{h,m}", "$(PROJECT_DIR)/HOSTConfig.{h,m}"

Upvotes: 6

Views: 2168

Answers (2)

bllakjakk
bllakjakk

Reputation: 5065

If what you are looking for is a way to access some header file(for config data) in your MainApp project from any Pod project, than the issue is just about providing proper path variable in pods project.

Just add

"$(PROJECT_DIR)/.."

along with the quotes to the User Header Search Paths entry build settings, and don't forget to select recursive.

This will allow the header search visibility of Pod to be extend to main project without changing the podfile.

Sample: enter image description here

Upvotes: 4

Pablo Carrillo Alvarez
Pablo Carrillo Alvarez

Reputation: 1182

If you just want to read values for a configuration probably the best way is to have some plist file and then check from the pod if that exist in the bundle or default to the one in the pod.

Upvotes: 1

Related Questions