Import Kanna in playground

眉间皱痕 提交于 2019-12-06 04:28:36

There is an interesting library in Github that allows run pods in Playground.It's still so young but it's very good. It's create a new project with the pod or pods installed and ready to test in the Playground.

I tested with your library and works fine:

//: 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"])
  }
}

I hope this help you.

@slabko (and others). In order to get this working:

I found this from cocoapods github issues.

Manually add the pod frameworks via Link Binary With Libraries on the non-framework target. Couple other caveats to keep in mind:

Classes or protocols defined in the pod that need to be accessible in the playground, must be marked public. When dealing with a pod you've created, adding a playground directly to your framework's project will probably not allow importing the pod. One workaround is to create a "sample" project, include the pod and add your playground to that (then manually add frameworks per above ^).

https://github.com/CocoaPods/CocoaPods/issues/2240 for reference if you want to know more

thanks to @davidbjames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!