在操场上导入 Kanna

Import Kanna in playground

有没有办法将 Kanna (https://github.com/tid-kijyun/Kanna) 添加到 XCode 中的 Playground? 我曾尝试通过 CocoaPods 手动安装它,但没有成功。我也尝试过将它打包到一个框架中,但仍然没有成功。 将不胜感激。

这些是我最常遇到的错误消息:

@slabko(和其他人)。为了让这个工作:

我从 c​​ocoapods github 问题中找到了这个。

通过 Link Binary With Libraries 在非框架目标上手动添加 pod 框架。 请记住其他注意事项:

类 或 pod 中定义的需要在 playground 中可访问的协议,必须标记为 public。 在处理您创建的 pod 时,将 playground 直接添加到框架的项目可能不允许导入 pod。一种解决方法是创建一个 "sample" 项目,包括 pod 并将您的游乐场添加到其中(然后按照上述 ^ 手动添加框架)。

https://github.com/CocoaPods/CocoaPods/issues/2240想了解更多的可以参考

感谢@davidbjames

Github 中有一个有趣的库,它允许 运行 pods 在 Playground.It 中还很年轻,但非常好。它创建了一个安装了 pod 或 pods 的新项目,并准备在 Playground 中进行测试。

我用你的图书馆测试过,工作正常:

//: Please build the scheme 'KannaPlayground' first
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

import Kanna

let html = "<html><a>Hello World</a></html>"

if let doc = Kanna.HTML(html: html, encoding: NSUTF8StringEncoding) {
  print(doc.title)

  // Search for nodes by CSS
  for link in doc.css("a, link") {
      print(link.text)
      print(link["href"])
  }

  // Search for nodes by XPath
  for link in doc.xpath("//a | //link") {
     print(link.text)
     print(link["href"])
  }
}

希望对你有所帮助。