使用迦太基在Xcode项目中添加依赖项的最快方法是什么。
以后如何添加或编辑依赖项。
答案 0 :(得分:3)
安装迦太基
打开终端
终端:cd〜/ Path / To / Folder Containing Project
创建迦太基文件为:
终端:触摸Cartfile
从项目文件夹中打开Cartfile文件并添加所需的依赖项
示例Cartfile文件
github“ Alamofire / Alamofire” == 4.5
github“ Alamofire / AlamofireImage”
编辑Cartfile文件后,将其保存。
从终端运行以下命令
终端:迦太基更新-平台iOS
xCode>构建阶段
/ usr / local / bin / carthage复制框架
$(SRCROOT)/Carthage/Build/iOS/DependencyName.framework
完成
答案 1 :(得分:0)
安装迦太基
//Homebrew
brew install carthage
在项目(Cartfile
)/工作区(.xcodeproj
)目录中创建.xcworkspace
文件
修改Cartfile
。添加必要的依赖性 == 回购
github "<owner>/<repo>" == <version>
运行carthage update
。高级逻辑:
`carthage update [dependency]` {
- reads `Cartfile`, resolves dependency graph and generates `Cartfile.resolved` to store a list of versions that will be actually built
//--no-use-binaries - this flag force a Carthage to not use a `Prebuilt framework`
//--no-build - this flag skip a building step - `carthage build`
`carthage bootstrap [dependency]` {
- reads `Cartfile.resolved`
`carthage checkout [dependency]` {
`carthage fetch <path>` {
- fetch dependency from `Cartfile.resolved` into `~/Library/Caches/org.carthage.CarthageKit/` folder
}
- checkout/move a dependency from `~/Library/Caches/org.carthage.CarthageKit/` to generated `Carthage/Checkouts` folder
}
`carthage build [dependency]` {
- builds all `shared frameworks schemes` from `Carthage/Checkouts` into generated `Carthage/Build` folder
//--no-skip-current - this flag also builds all `shared frameworks schemes` of a consumer workspace/project(in addition to `Carthage/Checkouts` folder)
}
}
}
将构建的框架拖放到General -> Frameworks and Libraries
运行下一个脚本。这一步很重要,因为迦太基构建使用fat
[About]处理lipo
二进制文件(arm64 ... + x86_64)。苹果拒绝使用它的应用程序。这就是为什么您应该添加此额外步骤来削减模拟器(x86_64)的体系结构的原因
Build Phases -> + -> New Run Script phase ->
// /usr/local/bin/carthage - path to Carthage, copy-frameworks - command which sets a necessary architecture and copies framework to an application bundle
Shell -> /usr/local/bin/carthage copy-frameworks
//path to a generated Carthage/Build
Input files -> + -> $(SRCROOT)/Carthage/Build/<platform>/<name>.framework
*应该从carthage
文件夹调用任何Cartfile
命令
答案 2 :(得分:0)
brew install carthage
Cartfile
,例如vim Cartfile
并粘贴:
github "AFNetworking/AFNetworking" ~> 4.0
carthage update --platform iOS
carthage update
命令。您可能需要运行例如carthage update --use-xcframeworks --platform iOS --no-use-binaries
代替。查看他们的自述文件。$project_dir/Carthage/Build
。您会发现 FrameworkName.framework
或 FrameworkName.xcframework
。 将 .framework
/ .xcframework
拖入您的 Xcode 项目(在项目导航器中)。