如何在快速的操场上使用与carthage一起进口的框架?

时间:2023-01-24 00:07:12

i have a swift project with some frameworks added via carthage. Is it possible to use those frameworks in playground inside project and how to use it, because

我有一个快速项目,通过carthage添加了一些框架。是否有可能在项目中使用这些框架以及如何使用它们,因为

import Argo

doesn't work :(

不工作:

4 个解决方案

#1


8  

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.

如果您想在现有的carthage项目中添加一个操场,您只需要将项目保存为一个工作区(文件>保存为workspace…),构建目标,您就完成了。

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:

如果您只想用第三方框架发布一个游乐场,那么您需要创建一个虚拟工作区。以下是一个使用RxSwift框架的操场的逐步示例:

  1. 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.

    创建一个新的Xcode项目,类型为跨平台>,其他>为空。它RxPlayground名称。这将创建这个结构rx游乐场/ rx游乐场。然后打开一个空白的Xcode。

  2. Download RxSwift with Carthage

    下载RxSwift迦太基

    • Create a Cartfile with this line: github "ReactiveX/RxSwift" "swift4.0"
    • 用这条线创建一个Cartfile: github“ReactiveX/RxSwift”“swift4.0”
    • Run Carthage with carthage update --platform iOS.
    • 运行Carthage与Carthage更新——平台iOS。
  3. Add a playground to the project.

    在项目中增加一个运动场。

    • Click File > New > Playground…
    • 点击文件>新的>操场…
    • Choose the iOS > Blank template and name it Rx.playground
    • 选择iOS >空白模板,命名为rx .游乐场
    • Right click the project node and choose “Add Files to RxPlayground”.
    • 右键单击项目节点,选择“向rx游乐场添加文件”。
    • Select the Rx.playground and add it.
    • 选择的处方。操场和添加它。
  4. Create a workspace

    创建一个工作区

    • Click File > Save as Workspace…
    • 点击文件>保存为工作区…
    • Save as Rx.xcworkspace
    • 另存为Rx.xcworkspace
  5. Copy the frameworks to the products directory.

    将框架复制到产品目录。

    • Close the project and open the Rx.xcworkspace
    • 关闭项目并打开Rx.xcworkspace
    • Create a Cross-platform > Other > Aggregate. Name it RxAggregate
    • 创建跨平台的>其他>聚合。命名为RxAggregate
    • Create a New Run Script Phase with the following content:
    • 创建一个新的运行脚本阶段,包含以下内容:
    cp -rv "${SRCROOT}/Carthage/Build/iOS/" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"

At this point, Xcode and the Finder look like this:

此时,Xcode和查找器看起来是这样的:

如何在快速的操场上使用与carthage一起进口的框架?

Note that Carthage/ and Cartfile.resolved appear when you run Carthage, Without them, your playground will be only a few Ks.

注意Carthage/和Cartfile。当你跑完迦太基,没有他们,你的操场将只有几克。

如何在快速的操场上使用与carthage一起进口的框架?

Lastly, build the project (⌘B). Now you can use the framework in your playground:

最后,构建项目(⌘B)。现在你可以在你的操场上使用这个框架:

//: 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.

有时你第一次构建(⌘B)Xcode没有注意到新的框架(叹气)。我所做的是单击目标并返回到源文件,或者重新打开项目。我无法解释为什么会这样。

#2


6  

In order for the framework to work within a playground, the project that produces the framework must be included in the workspace for your project. So to make this work you need to follow these steps:

为了使框架能够在一个操场上工作,生成框架的项目必须包含在项目的工作空间中。因此,要使这一工作,你需要遵循以下步骤:

  1. If your project is not inside a workspace, create a workspace for your project by choosing File > Save As Workspace in Xcode.
  2. 如果您的项目不在工作区中,请在Xcode中选择File > Save作为工作区,为您的项目创建工作区。
  3. Drag the .xcodeproj file from the Carthage/Checkouts folder into your workspace.
  4. 将.xcodeproj文件从Carthage/Checkouts文件夹拖到工作区中。
  5. Run the build action on your framework target.
  6. 在您的框架目标上运行构建操作。

#3


2  

I solved it by copying the built frameworks to the Built Products Directory, where Playgrounds in the workspace also searches for frameworks. Note: you also need to run lipo and strip away unused architectures from the FAT binaries.

我通过将构建框架复制到build Products目录来解决这个问题,在该目录中,工作区中的游乐场也会搜索框架。注意:您还需要运行lipo并从FAT二进制文件中删除未使用的架构。

See more here: https://github.com/richardnees/CarthagePlaygrounds

在这里看到更多:https://github.com/richardnees/CarthagePlaygrounds

#4


0  

Based @Jano's great answer (thanks for that), I created a fully functional playground to interact with Carthage frameworks:

基于@Jano的伟大回答(谢谢),我创建了一个功能完备的游乐场,与Carthage框架互动:

https://github.com/backslash-f/carthage-playground

https://github.com/backslash-f/carthage-playground

I included the Charts framework as an example:

我将图表框架作为一个例子:

如何在快速的操场上使用与carthage一起进口的框架?

I tested with Xcode 9.4.1 and (beta) 10.

我测试了Xcode 9.4.1和(beta) 10。

"Works on my machine." ????????

“在我的机器上工作。”????????

#1


8  

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.

如果您想在现有的carthage项目中添加一个操场,您只需要将项目保存为一个工作区(文件>保存为workspace…),构建目标,您就完成了。

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:

如果您只想用第三方框架发布一个游乐场,那么您需要创建一个虚拟工作区。以下是一个使用RxSwift框架的操场的逐步示例:

  1. 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.

    创建一个新的Xcode项目,类型为跨平台>,其他>为空。它RxPlayground名称。这将创建这个结构rx游乐场/ rx游乐场。然后打开一个空白的Xcode。

  2. Download RxSwift with Carthage

    下载RxSwift迦太基

    • Create a Cartfile with this line: github "ReactiveX/RxSwift" "swift4.0"
    • 用这条线创建一个Cartfile: github“ReactiveX/RxSwift”“swift4.0”
    • Run Carthage with carthage update --platform iOS.
    • 运行Carthage与Carthage更新——平台iOS。
  3. Add a playground to the project.

    在项目中增加一个运动场。

    • Click File > New > Playground…
    • 点击文件>新的>操场…
    • Choose the iOS > Blank template and name it Rx.playground
    • 选择iOS >空白模板,命名为rx .游乐场
    • Right click the project node and choose “Add Files to RxPlayground”.
    • 右键单击项目节点,选择“向rx游乐场添加文件”。
    • Select the Rx.playground and add it.
    • 选择的处方。操场和添加它。
  4. Create a workspace

    创建一个工作区

    • Click File > Save as Workspace…
    • 点击文件>保存为工作区…
    • Save as Rx.xcworkspace
    • 另存为Rx.xcworkspace
  5. Copy the frameworks to the products directory.

    将框架复制到产品目录。

    • Close the project and open the Rx.xcworkspace
    • 关闭项目并打开Rx.xcworkspace
    • Create a Cross-platform > Other > Aggregate. Name it RxAggregate
    • 创建跨平台的>其他>聚合。命名为RxAggregate
    • Create a New Run Script Phase with the following content:
    • 创建一个新的运行脚本阶段,包含以下内容:
    cp -rv "${SRCROOT}/Carthage/Build/iOS/" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"

At this point, Xcode and the Finder look like this:

此时,Xcode和查找器看起来是这样的:

如何在快速的操场上使用与carthage一起进口的框架?

Note that Carthage/ and Cartfile.resolved appear when you run Carthage, Without them, your playground will be only a few Ks.

注意Carthage/和Cartfile。当你跑完迦太基,没有他们,你的操场将只有几克。

如何在快速的操场上使用与carthage一起进口的框架?

Lastly, build the project (⌘B). Now you can use the framework in your playground:

最后,构建项目(⌘B)。现在你可以在你的操场上使用这个框架:

//: 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.

有时你第一次构建(⌘B)Xcode没有注意到新的框架(叹气)。我所做的是单击目标并返回到源文件,或者重新打开项目。我无法解释为什么会这样。

#2


6  

In order for the framework to work within a playground, the project that produces the framework must be included in the workspace for your project. So to make this work you need to follow these steps:

为了使框架能够在一个操场上工作,生成框架的项目必须包含在项目的工作空间中。因此,要使这一工作,你需要遵循以下步骤:

  1. If your project is not inside a workspace, create a workspace for your project by choosing File > Save As Workspace in Xcode.
  2. 如果您的项目不在工作区中,请在Xcode中选择File > Save作为工作区,为您的项目创建工作区。
  3. Drag the .xcodeproj file from the Carthage/Checkouts folder into your workspace.
  4. 将.xcodeproj文件从Carthage/Checkouts文件夹拖到工作区中。
  5. Run the build action on your framework target.
  6. 在您的框架目标上运行构建操作。

#3


2  

I solved it by copying the built frameworks to the Built Products Directory, where Playgrounds in the workspace also searches for frameworks. Note: you also need to run lipo and strip away unused architectures from the FAT binaries.

我通过将构建框架复制到build Products目录来解决这个问题,在该目录中,工作区中的游乐场也会搜索框架。注意:您还需要运行lipo并从FAT二进制文件中删除未使用的架构。

See more here: https://github.com/richardnees/CarthagePlaygrounds

在这里看到更多:https://github.com/richardnees/CarthagePlaygrounds

#4


0  

Based @Jano's great answer (thanks for that), I created a fully functional playground to interact with Carthage frameworks:

基于@Jano的伟大回答(谢谢),我创建了一个功能完备的游乐场,与Carthage框架互动:

https://github.com/backslash-f/carthage-playground

https://github.com/backslash-f/carthage-playground

I included the Charts framework as an example:

我将图表框架作为一个例子:

如何在快速的操场上使用与carthage一起进口的框架?

I tested with Xcode 9.4.1 and (beta) 10.

我测试了Xcode 9.4.1和(beta) 10。

"Works on my machine." ????????

“在我的机器上工作。”????????