Printing fails after outgoing a return value, and the content of the value is missing
baobao9999 opened this issue · comments
Description:
After calling this method, the array of XMLElement is obtained, and it can be printed normally in the current method, but after the return value is obtained, when the getElements method is called, an error will be reported when arr is printed
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
ele.attr("href") === ""
ele.stringValue == ""
private func getResult(_ xPath: String) -> Array {
let node : Fuzi.HTMLDocument = htmlNode
let nodeset = node.xpath(xPath)
let array = nodeset.map { $0 }
return array
}
public func getElements(_ xPath: String) -> Array<XMLElement>? {
if xPath.isEmpty { return [] }
do {
var jxNodes = Array<XMLElement>()
let ruleAnalyzes = RuleAnalyzer(xPath)
let rules = try ruleAnalyzes.splitRule("&&", "||", "%%")
if (rules.count == 1) {
if let arr = getResult(rules[0]){
return arr
}}
}
}
- Expected behaviour:
- test 1
ele.attr("href") === "/test1.html"
ele.stringValue == "test 1"
- Actual behaviour:
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Fuzi/Node.swift:122: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
ele.attr("href") === ""
ele.stringValue == ""
Environment
-
Package Manager:
- Carthage, version:
- CocoaPods, version:
- Manually
-
Fuzi version:3.1.3
-
Xcode version:15.0.1
How to reproduce:
xpath