I am trying to generate an XML document using Swift on Linux. But the following code doesn't compile:
let rootElement = XMLElement(name: "feed")
rootElement.setAttributesWith(["xmlns": ";])
I get the error 'XMLElement' (aka 'AnyObject') cannot be constructed because it has no accessible initializers
. I am surprised since XMLElement
is part of Foundation, which works on Linux, right? Is there something I am missing?
I am trying to generate an XML document using Swift on Linux. But the following code doesn't compile:
let rootElement = XMLElement(name: "feed")
rootElement.setAttributesWith(["xmlns": "http://www.w3./2005/Atom"])
I get the error 'XMLElement' (aka 'AnyObject') cannot be constructed because it has no accessible initializers
. I am surprised since XMLElement
is part of Foundation, which works on Linux, right? Is there something I am missing?
1 Answer
Reset to default 0The fix is to add the following guarded import to the file:
#if canImport(FoundationXML)
import FoundationXML
#endif
XMLElement
is only for macOS according to the documentation. While the Apple docs never mention Linux, just because a class is in Foundation for one particular platform does not mean it is available for other platforms. – HangarRash Commented yesterday