johngraham
johngraham

Reputation: 6490

CocoaPods importing a framework to source code

In my pod for iOS, I have a essentially items:

  1. Open-source classes (.m & .h files)
  2. MyFramework.framework (.framework directory, header files, and .bundle for resources)

One of the open-source classes calls import <MyFramework.MyFramework.h> so it can use the components of MyFramework in its implementation. But because of this, I'm having trouble getting the podspec to pass the spec lint test (pod spec lint MyCocoapod.podspec). When I run the spec lint validation, it says:

ERROR | [iOS] [xcodebuild]  .../MyFile.h:54:9: fatal error: 'MyFramework/MyFramework.h' file not found

While investigating, I noticed that the podspec does pass the spec lint validation if I remove that open-source class in the podspec's source_files section, s.source_files = 'MyFiles.{h,m}'. Any idea why my class can't import my custom framework during the spec lint validation?

The relevant code in the podspec looks like this:

s.preserve_paths      = 'myframework/MyFramework.framework'
s.frameworks          = 'Foundation', 'MyFramework'
s.xcconfig            = { 'FRAMEWORK_SEARCH_PATHS' => '$(SRCROOT)/myframework/' }
s.public_header_files = 'MyFramework.framework/Headers/*.h', 'SourceCode/*.h'
s.source_files        = 'SourceCode/*.{h,m}'  # Crashes here - Source_file imports MyFramework.h. If I take this out, it passes spec lint validation

Upvotes: 24

Views: 17126

Answers (2)

BigCheesy
BigCheesy

Reputation: 1138

To include a framework you can use:

s.vendored_frameworks = 'path/to/SomeFramework.framework'

To include bundle files do:

s.resources ='path/to/SomeBundle.bundle'

Upvotes: 9

Keith Smiley
Keith Smiley

Reputation: 63914

EDIT This process is now entirely handled by the vendored_frameworks option. This handles preserving the paths, the framework search paths, and linking to the project.

Upvotes: 30

Related Questions