我有一个 swift 项目,其中包含通过 carthage 添加的一些框架。是否可以在项目内部的操场上使用这些框架以及如何使用它,因为
import Argo
不工作:(
我有一个 swift 项目,其中包含通过 carthage 添加的一些框架。是否可以在项目内部的操场上使用这些框架以及如何使用它,因为
import Argo
不工作:(
This stopped working at some point. Sigh
What I do now is
github "ReactiveX/RxSwift"
and run carthage update --platform iOS
At this point I’m able to run the playground files.
♂️</p>
A playground has access to external frameworks if it is part of a workspace that builds a target configured to access those frameworks.
If you want to add a playground to an existing carthage project, you only need to save the project as a workspace (File > Save as Workspace…), build the target, and you are done.
If you just want to distribute a playground with third party frameworks, you need to create a dummy workspace. Here is a step by step example for a playground with the RxSwift framework:
Create a new Xcode project of type Cross-platform > Other > Empty. Name it RxPlayground.
This will create this structure RxPlayground/RxPlayground.xcodeproj and open a blank Xcode.
Download RxSwift with Carthage
github "ReactiveX/RxSwift" "swift4.0"
carthage update --platform iOS
. Add a playground to the project.
Create a workspace
Copy the frameworks to the products directory.
cp -rv "${SRCROOT}/Carthage/Build/iOS/" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"
At this point, Xcode and the Finder look like this:
Note that Carthage/ and Cartfile.resolved appear when you run Carthage, Without them, your playground will be only a few Ks.
Lastly, build the project (⌘B). Now you can use the framework in your playground:
//: Playground - noun: a place where people can play
import RxSwift
_ = Observable<Void>.empty()
.subscribe(onCompleted: {
print("Completed")
})
Sometimes the first time you build (⌘B) Xcode doesn’t notice the new framework (sigh). What I do is click on the target and back to a source file, or re-open the project. I don’t have an explanation why this happens.
为了使框架在 Playground 中工作,生成框架的项目必须包含在项目的工作区中。因此,要完成这项工作,您需要执行以下步骤:
File > Save As Workspace
在 Xcode 中选择来为您的项目创建一个工作区。Carthage/Checkouts
文件夹拖到您的工作区。基于@Jano 的出色回答(感谢),我创建了一个功能齐全的游乐场来与 Carthage 框架进行交互:
https://github.com/backslash-f/carthage-playground
我以Charts框架为例:
我用最新的 Xcode 进行了测试。
“在我的机器上工作。 ”
我通过将构建的框架复制到构建产品目录来解决它,工作区中的 Playgrounds 也在其中搜索框架。注意:您还需要运行 lipo 并从 FAT 二进制文件中删除未使用的架构。
在此处查看更多信息: https ://github.com/richardnees/CarthagePlaygrounds
找到了如何做到这一点,而无需转换为工作区并将 Carthage/Checkouts 文件夹中的 .xcodeproj 文件添加到您的项目中。如果您有一些包含您想在 Playground 中使用的所有源的框架目标,则此方法有效。该框架必须在您的主要目标的“嵌入式框架”中。
这对我有用