ios - 在 Swift 中使用 hpple

标签 ios swift hpple

我在 Swift 中使用 hpple,并希望使用相同的语法。

Objective-C 完美运行:

myElement.title = [[element firstChild] content];

Swift 无法编译:

myelement.title = element.firstchild.content

我收到错误 TFHppleElement!没有名为“content”的成员

另一方面,以下工作正常,表明特别是 myElement 和 hpple 似乎设置正确:

myElement.url = element.objectForKey("href")  // Works fine

有什么想法吗?

最佳答案

firstchild 可能会返回一个可选的,因为可能没有第一个 child 。您需要打开可选的包装才能使用它。我建议:

if let content = element.firstchild?.content {
    myelement.title = content
}

如果 myelement.title 也是可选的,你可以这样做:

myelement.title = element.firstchild?.content

关于ios - 在 Swift 中使用 hpple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31762606/

相关文章:

ios - 如何将 ImageView 包含到自定义 Segue 中?

ios - Swift 3 - iOS 11.2 上的 UICollectionview 问题

ios - hpple xpath 问题

ios - Safari移动插件开发

ios - 使用 Xcode 4.2 部署 iOS3.1.3

ios - 从网站调用警报 View

ios - UITableView 在有数据之前没有弹出数据

ios - 快速创建表

ios - swift 中的 iToast 替代品

html - Hpple 在 iOS 中使用复杂的 HTML