Recently I have updated my project to support Swift 4.1, and I found an incompatible issue, caused a crash.
The previous version code looks like this:
public enum XMLSubscriptResult {
/// some other implementation ....
public var xmlList:[XML]? {
do {
return try getXMLList()
} catch {
return nil
}
}
public func getXMLList() throws -> [XML] {
switch self {
case .null(let error):
throw XMLError.subscriptFailue(error)
case .string(_, let path):
throw XMLError.subscriptFailue("can not get list from attribute, from keyChain: \(path)")
case .xml(let xml, _): return [xml]
case .array(let xmls, _): return xmls
}
}
}
the reason caused the crash is because in attribute getter called a method that throws an error. After I change the attribute getter as below:
public var xmlList:[XML]? {
switch self {
case .null(_):
return nil
case .string(_, _):
return nil
case .xml(let xml, _): return [xml]
case .array(let xmls, _): return xmls
}
}
the error is gone ~