title: Writing a CocoaPod when depending on React-Core (React/RCTBridge+Private.h)
body: <p>I am co-authoring a React Native library that has a dependency on the RCTBridge. In the process of implementing support for <a href="https://github.com/react-native-community/cli/blob/master/docs/autolinking.md" rel="nofollow noreferrer">autolinking</a> I'm writing a <a href="https://guides.cocoapods.org/syntax/podspec.html" rel="nofollow noreferrer">Podspec</a> and wondering whats the best way to declare the dependency on React.</p>
  
  <h2>Concern #1</h2>
  
  <p>My current approach is having a PodSpec dependency on the (deprecated) React pod (which I believe will be resolved to the dev pod specified by the consuming app's Podfile) and adding the path of the React headers to the xcconfig's <code>HEADER_SEARCH_PATHS</code>, basically:</p>
  
  <pre class="lang-rb prettyprint-override"><code>app_path = File.expand_path('../..', __dir__)
  
  Pod::Spec.new do |s|
    # ... here goes a lot of other stuff
    s.dependency 'React'
    s.pod_target_xcconfig    = { "'#{app_path}/ios/Pods/Headers/Public/React-Core'" }
  end
  </code></pre>
  
  <p>This works, but I don't like that it makes an assumption on the location of the path of my node modules path relative to the consuming apps ios and Pods folder.
  In practice we could use <code>'"$(PODS_ROOT)/Headers/Public/React-Core/"'</code> instead, but this breaks linting the library (running <code>pod lib lint</code>) because the test app produced during this linting, doesn't have a Podfile which depends on the local dev pod as a regular React Native app's Podfile would.</p>
  
  <h2>Concern #2</h2>
  
  <p>We would like our library to support scenarios where the consumer uses frameworks via the <a href="https://guides.cocoapods.org/syntax/podfile.html#use_frameworks_bang" rel="nofollow noreferrer"><code>use_frameworks!</code></a>, which bundles React into a framework directory. This means the header will no longer be located in the <code>ios/Pods/Headers</code> folder and our pod needs to depend on the <code>React</code> framework instead:</p>
  
  <pre class="lang-rb prettyprint-override"><code>Pod::Spec.new do |s|
    # ... here goes a lot of other stuff
    s.framework 'React'
    s.dependency 'React'
  end
  </code></pre>
  
  <p>But when adding this, the consumers Podfile must call <code>use_frameworks!</code>.</p>
  
  <p>To my knowledge there is:</p>
  
  <ol>
  <li>No way of "gently" depending on a framework (using it only if its there).</li>
  <li>No elegant way of determining if a consuming Podfile is calling <code>use_frameworks!</code>, from within a Podspec.</li>
  </ol>
  
  <p>Is this true?</p>
  
  <p>My current (and super hacky) way around this, is to assume the location of the consumers Podfile and check for the existence of "use_framework!":</p>
  
  <pre class="lang-rb prettyprint-override"><code>app_path = File.expand_path('../..', __dir__)
  podfile_path = File.expand_path('ios/Podfile', app_path)
  begin
    podfile = File.read(podfile_path)
    uses_frameworks = podfile.scan(/\n\s*use_frameworks!\n/).any?
  rescue
    uses_frameworks = false
  end
  
  Pod::Spec.new do |s|
    # ... here goes a lot of other stuff
    # Conditionally depend on the React framework
    if uses_frameworks
      s.framework 'React'
    end
    # Depending on the React pod is still needed for some reason ...
    s.dependency 'React'
  end
  </code></pre>
  
  <h2>My question for you</h2>
  
  <p>Do you have any ideas on more elegant ways of achieving the goals of importing the "React/RCTBridge+Private.h" header and support consumers regardless of them using "use_frameworks!" or not?</p>