我正在开发一个涉及一些 XML 解析的自定义框架,使用 Kanna框架。每当我尝试将我的框架导入 playground 时,playground 就会崩溃并出现以下错误:
Playground execution failed: expression failed to parse, unknown error
* thread #1: tid = 0x4e9448, 0x00000001074bf360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x00000001074bf360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground
frame #1: 0x00000001074bd22a com.apple.dt.Xcode.PlaygroundStub-macosx`-[PlaygroundViewBridgeService execute] + 90
frame #2: 0x00007fffb4fc03ec CoreFoundation`__invoking___ + 140
frame #3: 0x00007fffb4fc0271 CoreFoundation`-[NSInvocation invoke] + 289
frame #4: 0x00007fffb4fd97a6 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
frame #5: 0x00007fffc86ca95b ViewBridge`__68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke + 47
frame #6: 0x00007fffc86e9f4c ViewBridge`__runAnimationGroup_block_invoke + 21
...
我正在开发的框架运行良好(它按预期构建和运行单元测试),但无法在 Playground 上使用它是一种痛苦。
我已经在 GitHub 上提供了一个示例项目,其中包含有关复制问题的说明以及完整的堆栈跟踪:https://github.com/noahcgreen/XMLTest .如果从“XMLTest.swift”源文件中删除 import Kanna
,错误就会消失。
到目前为止我已经尝试过:
- 使用Fuzi框架而不是 Kanna,
- 安装 CocoaPods 而不是 Carthage,
- 在我的设备上更新 libxml2(使用 Homebrew),以及
- 在不同的(和新的)设备上重新安装 XCode,
全部失败。我在这里束手无策。我做错了什么?
最佳答案
可能会对想要将 libxml2 库添加到 Xcode Playground 的人有所帮助。
请按照以下步骤操作:
- 创建一个空的工作区。
- 在工作区中添加一个 Playground 。
- 向工作区添加一个空框架,并将
"$(SDKROOT)/usr/include/libxml2"
添加到'SWIFT_INCLUDE_PATHS'
中的'Build设置的
。 - 在 playground 页面上添加
'import libxml2'
。
关于xml - 使用 XML 解析 Swift 库时,Playgrounds 崩溃并显示 "unknown error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41679487/