Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any downside to setting DEFINES_MODULE = YES in my podspec?

Tags:

ios

cocoapods

Some Cocoapods, e.g. YLTableView, don't set 'DEFINES_MODULE' => 'YES' as part of their pod_target_xcconfig. This means that, for example, import YLTableView doesn't work in Swift unless you set :modular_headers => true in your Podfile like so:

pod 'YLTableView', '~> 2.2.0', :modular_headers => true

If I'm writing a podspec, is there any reason I shouldn't include DEFINES_MODULE in my config like so?

ss.pod_target_xcconfig = { "DEFINES_MODULE" => "YES" }

It seems to me that this doesn't have any negative effect, and it enables Swift users to consume my library more easily.

like image 218
Noah Gilmore Avatar asked Jul 08 '18 00:07

Noah Gilmore


People also ask

What is Podspec file?

A Podspec file, or Spec, describes a version of a Pod library. It includes details about where the source files are located, which files to use, the build settings to apply, dependencies, frameworks used and other general metadata such as the name, version and description for the Pod.

How do I add files to Podspec?

To create a Podspec, navigate to your project file in the Terminal. Run the following command to create the file: touch FantasticView. podspec . Now open the file using an editor.

What is Podspec in CocoaPods?

A Podspec, or Spec, describes a version of a Pod library. One Pod, over the course of time, will have many Specs. 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.

What is Use_frameworks in Podfile?

use_frameworks! in the Podfile means that we want the listed frameworks to be dynamically installed instead as static frameworks.


1 Answers

There is one known issue (with workarounds): https://github.com/CocoaPods/CocoaPods/issues/7584. It may cause issues for users importing your Objective-C lib headers directly in their Precompiled Headers (*.pch). You may workaround it by including an empty swift file in your lib source files. Chances are there will be a clean fix in a future version of CocoaPods.


Otherwise, there is no real downside. It enables stricter search paths for imports at build time, which means:

  • either it builds, and it works like before (and as bonus you can now find it with @import in ObjC or import in Swift)
  • either it doesn't build anymore, and consequently you can't publish the podspec anymore

From the blog post regarding CocoaPods 1.5.0 release:

[...] CocoaPods allowed any pod to import any other pod with un-namespaced quote imports.

For example, pod B could have code that had a #import "A.h" statement, and CocoaPods will create build settings that will allow such an import to succeed. Imports such as these, however, will not work if you try to add module maps to these pods. We tried to automatically generate module maps for static libraries many years ago, and it broke some pods, so we had to revert.

In this release, you will be able to opt into stricter header search paths (and module map generation for Objective-C pods). As a pod author, you can add 'DEFINES_MODULE' => 'YES' to your pod_target_xcconfig. [...]

like image 85
Cœur Avatar answered Oct 11 '22 17:10

Cœur