我如何在我的cocoapod源文件中包含Alamofire(Web请求容器,如AFNetworking)?我的cocoapod中有一个服务需要使用Alamofire发出Web请求,我的cocoapod似乎没有可以看到的podfile,所以我不知道如何将依赖项添加到我的cocoapod中。
我正在使用pod lib create
创建一个cocoapod,每当我在任何文件中导入Alamofire时,构建都会失败。在一个普通的项目中,我只是将Alamofire添加到我的podfile中,但这是一个cocoapod,所以我不知道在哪里添加依赖项,或者如何使它成功构建。
我遵循了指南here,但是它并没有说明将另一个容器导入我的cocoapod的文件中。
我的目录结构如下:
MyLib.podspec
Example/
MyLib example project
Pod/
Source files for my cocoapod
如果您的广告连播取决于其他广告连播,则可以在广告连播的.podspec
文件中进行定义。您可以在此处添加依赖项。
以RealmSwift的podspec文件为例。 RealmSwift容器与Realm容器具有依赖性。这是在RealmSwift.podspec中定义的:
Pod::Spec.new do |s|
s.name = 'RealmSwift'
s.version = `sh build.sh get-version`
s.summary = 'Realm is a modern data framework & database for iOS & OS X.'
s.description = <<-DESC
The Realm database, for Swift. (If you want to use Realm from Objective-C, see the “Realm” pod.)
Realm is a mobile database: a replacement for Core Data & SQLite. You can use it on iOS & OS X. Realm is not an ORM on top SQLite: instead it uses its own persistence engine, built for simplicity (& speed). Learn more and get help at https://realm.io
DESC
s.homepage = "https://realm.io"
s.source = { :git => 'https://github.com/realm/realm-cocoa.git', :tag => "v#{s.version}" }
s.author = { 'Realm' => '[email protected]' }
s.requires_arc = true
s.social_media_url = 'https://twitter.com/realm'
s.documentation_url = "https://realm.io/docs/swift/#{s.version}"
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
# ↓↓↓ THIS IS WHERE YOU DEFINE THE DEPENDENCY TO ANOTHER POD ↓↓↓
s.dependency 'Realm', "= #{s.version}"
# ↑↑↑ THIS IS WHERE YOU DEFINE THE DEPENDENCY TO ANOTHER POD ↑↑↑
s.source_files = 'RealmSwift/*.swift'
s.prepare_command = 'sh build.sh cocoapods-setup without-core'
s.preserve_paths = %w(build.sh)
s.pod_target_xcconfig = { 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES',
'APPLICATION_EXTENSION_API_ONLY' => 'YES' }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
s.watchos.deployment_target = '2.0' if s.respond_to?(:watchos)
end
您应该签出AlamofireImage项目。它使用迦太基将Alamofire子模块添加到项目中。然后将Alamofire项目作为依赖项添加到AlamofireImage项目。
AlamofireImage.podspec还演示了如何添加Alamofire作为CocoaPods的依赖项。如果您完全遵循AlamofireImage项目结构,那么您将立即启动并运行。以下是一些有用的命令,可助您一臂之力:
github "Alamofire/Alamofire" ~> 3.0
brew update
brew doctor
brew install carthage
// or
brew upgrade carthage
carthage update --no-build --use-submodules
希望有帮助!
如果创建了pod
,并在.podspec
文件中尝试添加dependency
(例如Alamofire,RealmSwift ..),则应转到Example/..
项目,该项目应为pod install
,以使自定义pod
的.podspec所需的依赖项对您的自定义Pod /框架中的.swift文件可见。
pod项目文件夹层次结构的典型示例是:
- MyLib/
- _Pods.xcodeproj
- Example/ // <-- do a pod install under this folder in order to get the dependencies declared in your .podspec
- Podfile
- MyLib.xcodeproj
- MyLib.xcworkspace
- MyLib/
- Classes/ // <-- folder with pod specific logic that also uses Alamofire
- Assets/
- MyLib.podspec // <-- your podspec with dependencies (Alamofire..)