最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - XMLElement has no accessible initializers on Linux - Stack Overflow

programmeradmin5浏览0评论

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?

Share Improve this question asked yesterday Kevin RenskersKevin Renskers 5,9305 gold badges58 silver badges120 bronze badges 2
  • 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
  • Since the docs never mention Linux, how are you supposed to know if something works on Linux or not? – Kevin Renskers Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

The fix is to add the following guarded import to the file:

#if canImport(FoundationXML)
import FoundationXML
#endif
发布评论

评论列表(0)

  1. 暂无评论