Search code examples
iosswiftxcodecocoapodspodspec

Xcode Workspace - Not finding imports from framework development pod


I've set up a workspace with two Swift projects in it: one a framework I'm developing, the other a demo app for the framework.

Podfile looks like this:

platform :ios, '9.0'
workspace 'foo.xcworkspace'

target 'framework' do
    project 'framework.xcodeproj'
end

target :'demo' do
    project 'demo/demo.xcodeproj'
    pod 'framework', :path => 'framework.podspec'
end

the .podspec file looks like this:

Pod::Spec.new do |s|
    s.name         = 'framework'
    s.authors      = { "foo author" }
    s.version      = '0.1.0'
    s.summary      = 'foo summary.'
    s.homepage     = 'foo homepage'
    s.platform     =  :ios, '9.0'
    s.license      = {
        :type => "Proprietary",
        :file => "LICENSE"
    }
    s.source       = {
        :git => 'https://url.to/foo.git',
        :tag => s.version.to_s
    }
    s.source_files = 'framework/framework/**/*.{swift,h,m}'
    s.requires_arc = true
    s.weak_framework = "XCTest"
    s.pod_target_xcconfig = {
        'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"',
    }
end

After running pod install, Xcode/AppCode can still not see the classes from the framework project. So if I add a manual import to a class in the demo app and try to compile, it fails with:

Error:(13, 21) use of undeclared type 'FooClass'

What do I have to do to properly have the demo app project see the classes from the framework project generated pod?


Solution

  • I finally resolved this issue:

    1. Make sure the min. required iOS is defined in Podfile, e.g.:

      platform :ios, '10.0'

    2. Add any third-party pods also to the podspec file, e.g.:

      spec.dependency 'Alamofire', '~> 4.5' spec.dependency 'Serpent', '~> 1.0'

    3. If doing pod install without the use_frameworks! it will mess up some things (see this answer: ld: framework not found Pods). So in between I got these invalid Pod xconfigs that I had to delete and then do a clean and pod install.

    4. Make sure to build the framework project at least once and then the demo source should find the import to the framework pod name!

    5. Make sure that all classes are correctly added to their target, especially classes in the test target should not have been added to the app target accidentally.

    After all is said and done, having worked with a multitude of IDEs and development technologies, Xcode and Cocoapods can only be summed up as one giant clusterf*** of an accident!