6

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}"
Community
  • 1
  • 1
timpone
  • 19,235
  • 36
  • 121
  • 211
  • It doesn't matter if it's a private or public pod, it should do everything automatically after invoking pod update or pod install form the terminal, would you please make your case clearer? – Boda Jan 28 '15 at 10:47
  • so by main app, I mean that HOSTConfig.h/m would be provided by the person writing the app. I worked around this by by just having a config object that you instantiate before using our objects; the Pods.***.xconfig would look like the place for this to happen. – timpone Jan 28 '15 at 15:43
  • 1
    You shouldn't modify the .xconfig files that is generated by the cocoapods library because your modifications will be removed when you execute pod update or install the next time – Boda Jan 31 '15 at 11:54
  • ths Aubada - have learned A LOT about cocapods since I set bounty – timpone Feb 09 '15 at 22:17

2 Answers2

4

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

bllakjakk
  • 5,045
  • 1
  • 18
  • 28
  • cool - I think this is what I need; one question - would there be a way to have the same variable locally in the pod. Like I want `HEXHost()` to be either the `dev` or `production` so should be set in the MainApp config but for testing purposes would like to have a HEXHost in the pod such that it would return that. Perhaps a variable in the Pod like `HEXPodHost` which returns `HEXHost` from the MainApp if it exists and if not a locally defined value. Would that be possible? – timpone Feb 09 '15 at 22:24
  • Generally we use #define in config file to declare PROD or DEV version i.e. #define GLD_STAGING_SERVER_ON but you can also use some variable in your class and that would be overridden by your POD's config file. – bllakjakk Feb 10 '15 at 02:49
  • one issue I am noticing is that I need to readd this each time after I `pod update MYPod`; is there a workaround for this? – timpone Feb 10 '15 at 04:20
  • Yes, pod update will definitely overwrite your changes. What you could do is fork the project on Github, make the changes in your fork and point Cocoapods to the fork. (But not preferred way, as your code may have private data). – bllakjakk Feb 10 '15 at 04:49
  • so the CocoaPod is a private repo (just using for code distribution), so what changes would I need to make this happen? Is it possible to specify in a .podspec to add this User Search Path? like possibly adding `s.source_files = [$(PROJECT_DIR)'/MainAppConfig.{h,m]','Library/src/**/*.{h,m}']` or something? – timpone Feb 10 '15 at 05:27
  • Sample: http://stackoverflow.com/questions/12393470/use-a-fork-of-restkit-on-github-via-cocoapod but keep in mind your private data. – bllakjakk Feb 10 '15 at 05:36
  • so, I'm not getting what the point of that sample (my fault). I've updated to include the exact HOSTConfig in the podspec in edit #1 above. Is it possible to use spec.xconfig to add this? – timpone Feb 10 '15 at 06:16
  • added this question: http://stackoverflow.com/questions/28425765/add-a-user-header-search-path-to-a-podspec – timpone Feb 10 '15 at 06:53
1

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.