Import Kanna in playground

2 Solutions Collect From Internet About “Import Kanna in playground”

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.

  • ThisCouldBeUsButYouPlaying

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