【问题标题】:Dependent frameworks with playgrounds带有游乐场的依赖框架
【发布时间】:2017-01-22 19:12:46
【问题描述】:

假设我有 2 个框架:

  • MyApp.framework
  • FancyLabels.framework

MyApp.framework 有一个故事板,它使用 FancyLabels.framework 中的类。

如果我创建一个链接和嵌入两个框架的应用程序目标,我可以从 MyApp.framework 实例化视图控制器没有问题。

但如果我尝试在 Playground 中从 MyApp.framework 实例化视图控制器,它无法从 FancyLabels.framework 中找到类。

我的游乐场代码:

//: Playground - noun: a place where people can play

import UIKit
import MyApp
import FancyLabels

let bundle = Bundle(for: MyAppViewController.self)
let storyboard = UIStoryboard(name: "Main", bundle: bundle)
let vc = storyboard.instantiateViewController(withIdentifier: "MyAppViewController")
let view = vc.view

控制台中的输出:

2017-01-22 19:18:17.016 MyPlayground[98260:3124481] Unknown class _TtC18FancyLabels11StyledLabel in Interface Builder file.
2017-01-22 19:18:17.037 MyPlayground[98260:3124481] Failed to set (styleString) user defined inspected property on (UILabel): [<UILabel 0x7fcf175017c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key styleString.

【问题讨论】:

    标签: ios swift swift-playground xcplayground


    【解决方案1】:

    我也一直在努力寻找最好的方法:(

    我找到的最佳解决方案是创建一个空白/空工作区,您可以在其中添加框架(只需将它们拖到工作区中,就像添加到常规项目中一样),然后还将游乐场添加到工作区。

    您无需打开 Playground,而是打开工作区并在该上下文中使用 Playground。

    第一次在工作区中打开 Playground 时会出现错误提示找不到框架,但在运行 build 后框架可用。

    另一个问题是,当您从该工作区访问框架时,任何其他使用该框架的项目也需要关闭。

    如果您想查看示例设置,可以在此处查看我的项目中的“Playgrounds”文件夹:https://github.com/mathewsanders/Mustard/tree/master/Playgrounds

    很想听听其他人是否找到了更好的方法,因为在使用工作区时必须关闭其他项目的限制非常烦人。

    【讨论】:

    • 感谢您的回答@MathewS。在我的具体案例中,问题是“FancyLabels”框架使用的是预建的 Carthage 框架。我也设法在不使用空白/空工作区的情况下完成这项工作。看看我回答中的 github 链接。
    【解决方案2】:

    终于想通了。问题是我的“FancyLabels”框架通过 Carthage (XCGLogger) 使用了预构建的框架。解决方案是按照适当的步骤在游乐场中使用 Carthage 框架,即将框架的项目从 Carthage/Checkouts 添加到我的工作区并构建它。然后一切都按预期工作,甚至是框架项目内的游乐场,在 MyApp 框架的故事板/xibs 中充分使用了 FancyLabels。

    对于遇到这个问题的人,即使没有 Carthage 也很难设置,我已经做了一个快速工作示例,说明如何在此处设置:https://github.com/mfclarke/NestedFrameworksInPlaygrounds/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 2013-04-29
      • 2020-01-05
      • 2021-01-02
      相关资源
      最近更新 更多