问题
Is there a way to add Kanna (https://github.com/tid-kijyun/Kanna) to Playground in XCode? I have tried to install it manually and via CocoaPods, but with no luck. I have also tried to pack it inside a Framework, but still no luck. Would appreciate any input.
These are the error messages I am most often encountering:
回答1:
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.
回答2:
@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
来源:https://stackoverflow.com/questions/35735193/import-kanna-in-playground