ios - 带有 playground 的依赖框架

标签 ios swift swift-playground xcplayground

假设我有 2 个框架:

  • MyApp.framework
  • FancyLabels.framework

MyApp.framework 有一个 Storyboard,它使用 FancyLabels.framework 中的类。

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

但是如果我尝试在 Playground 上从 MyApp.framework 实例化一个 View Controller ,它无法从 FancyLabels.framework 中找到类。

我的 Playground 代码:

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

最佳答案

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

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

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

第一次在工作区打开 playground 会报错说找不到框架,但是运行 build 后框架可用。

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

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

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

关于ios - 带有 playground 的依赖框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41795077/

相关文章:

ios - 将 JSON 转换为自定义对象时出错

ios - iPhone 来电时如何截屏

swift - 将字典传递给 init 方法

ios - 在 Xcode 8 中隐式展开可选分配

swift-playground - Xcode 7 Playground 执行 EXC_BAD_ACCESS

swift - Int... 和 Int[] 的区别

ios - 将字符串从 TableView 单元格传递到 Swift 3 中的 View Controller

ios - 休息套件 : Not able to perform mapping using coredata

ios - 垂直对齐 NSMutableAttributedString 中的 NSTextAttachment

swift - 无法在 Swift playground 中加载纹理图集?