According to https://www.w3schools.com/xml/schema_dtypes_misc.asp: "Legal values for boolean are true, false, 1 (which indicates true), and 0 (which indicates false)." Swift's Bool() returns nil for 1 and 0 so we can't use it.
I propose adding code something like the following in Element.swift:
/// Boolean representation of `value` property (`nil` if `value` can't be represented as Bool).
open var bool: Bool? {
if string == "true" || string == "1" { return true }
if string == "false" || string == "0" { return false }
return nil
}
And adding tests for the 0 & 1 case in plant_catalog.xml and AEXMLTests.swift:
func testBoolValue() {
let firstTrueString = plantsDocument.root["PLANT"]["TRUESTRING"].bool
XCTAssertEqual(firstTrueString, true, "Should be able to cast element value as Bool.")
let firstFalseString = plantsDocument.root["PLANT"]["FALSESTRING"].bool
XCTAssertEqual(firstFalseString, false, "Should be able to cast element value as Bool.")
let firstTrueInt = plantsDocument.root["PLANT"]["TRUEINT"].bool
XCTAssertEqual(firstTrueInt, true, "Should be able to cast element value as Bool.")
let firstFalseInt = plantsDocument.root["PLANT"]["FALSEINT"].bool
XCTAssertEqual(firstFalseInt, false, "Should be able to cast element value as Bool.")
let firstElementWithoutValue = plantsDocument.root["ELEMENTWITHOUTVALUE"].bool
XCTAssertNil(firstElementWithoutValue, "Should be able to return nil if value can't be represented as Bool.")
}
According to https://www.w3schools.com/xml/schema_dtypes_misc.asp: "Legal values for boolean are true, false, 1 (which indicates true), and 0 (which indicates false)." Swift's Bool() returns nil for 1 and 0 so we can't use it.
I propose adding code something like the following in Element.swift:
And adding tests for the 0 & 1 case in plant_catalog.xml and AEXMLTests.swift: