问题
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?
回答1:
Try using inherit! :search_paths
on the demo target
This means they don't get their own copies of the pods but can see they exist via the header files.
platform :ios, '9.0'
workspace 'foo.xcworkspace'
target :framework do
project 'framework.xcodeproj'
end
target :demo do
inherit! :search_paths
project 'demo/demo.xcodeproj'
pod 'framework', :path => 'framework.podspec'
end
untested but perhaps worth a shot
回答2:
If you install a Cocoapod don't use the file with .xcodeproj to open your project anymore, but the newly created .workspace in the same folder.
回答3:
I finally resolved this issue:
Make sure the min. required iOS is defined in Podfile, e.g.:
platform :ios, '10.0'
Add any third-party pods also to the podspec file, e.g.:
spec.dependency 'Alamofire', '~> 4.5' spec.dependency 'Serpent', '~> 1.0'
If doing
pod install
without theuse_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.Make sure to build the framework project at least once and then the demo source should find the import to the framework pod name!
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!
来源:https://stackoverflow.com/questions/45074383/xcode-workspace-not-finding-imports-from-framework-development-pod