<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Indeed it works, but I don’t get it.<div class="">What’s the difference?</div><div class=""><br class=""></div><div class="">-g.</div><div class=""><br class=""></div><div class="">PS: Btw, my original code was giving `seg-fault: 11` even on macOS.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 5 Sep 2017, at 10:53 AM, CK TUNG via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">This revised code, as below, works without segmentation fault</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br data-mce-bogus="1" class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">import</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>Foundation</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">class</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>ParserDelegate:<span class="Apple-converted-space">&nbsp;</span></span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">NSObject</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">,<span class="Apple-converted-space">&nbsp;</span></span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">XMLParserDelegate</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>{</span></div><p class="p2" style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>startParsing(</span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>xml:</span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>data = xml.</span><span class="s5" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">data</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">(using: .</span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">utf8</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">)!</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>xmlParser =<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">XMLParser</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">(data: data)</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; xmlParser.</span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">delegate</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>=<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">self</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; xmlParser.</span><span class="s5" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">parse</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">()</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div><p class="p2" style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>parserDidStartDocument(</span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>parser:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">XMLParser</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span class="s3" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s5" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">print</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">"Starting document"</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div><p class="p2" style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>parser(</span><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>parser:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">XMLParser</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">, didStartElement elementName:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">, namespaceURI:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">?, qualifiedName qName:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">?, attributes attributeDict: [</span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>:<span class="Apple-converted-space">&nbsp;</span></span><span class="s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">]) {</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="s5" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">print</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="s6" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"***<span class="Apple-converted-space">&nbsp;</span></span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="s6" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">(</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">elementName</span><span class="s6" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">)"</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span class="s2" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>xml =<span class="Apple-converted-space">&nbsp;</span></span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">"&lt;root&gt;&lt;title name=\"test\"&gt;George&lt;/title&gt;&lt;/root&gt;"</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span class="s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>test =<span class="Apple-converted-space">&nbsp;</span></span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">ParserDelegate</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">()</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span class="s7" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">test</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="s2" style="font-variant-ligatures: no-common-ligatures;">startParsing</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="s7" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">xml</span><span class="s3" style="font-variant-ligatures: no-common-ligatures;">)</span></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="msg-quote"><div class="_stretch"><span class="body-text-content">As an example, this SegFaults:<br class=""><br class="">import Foundation<br class=""><br class="">class ParserDelegate: NSObject, XMLParserDelegate {<br class="">func parserDidStartDocument(_ parser: XMLParser) {<br class="">print("Starting document")<br class="">}<br class=""><br class="">func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {<br class="">print("*** \(elementName)")<br class="">}<br class="">}<br class=""><br class="">let xml = "&lt;root&gt;&lt;title name=\"test\"&gt;George&lt;/title&gt;&lt;/root&gt;"<br class="">let data = xml.data(using: .utf8)!<br class="">let xmlParser = XMLParser(data: data)<br class="">xmlParser.delegate = ParserDelegate()<br class="">xmlParser.parse()<br class=""><br class=""><blockquote type="cite" class="quoted-plain-text">On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis &lt;<a href="mailto:george.moschovitis@icloud.com" class="">george.moschovitis@icloud.com</a>&gt; wrote:</blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">Hi,</blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">I would like to parse an RSS feed using Swift 3.1 on Linux.</blockquote><blockquote type="cite" class="quoted-plain-text">I tried to use Foundations’s XML but I only managed to get segmentation faults.</blockquote><blockquote type="cite" class="quoted-plain-text">Is this supposed to work on Linux? I have only seen examples on iOS.</blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">Apart from that a quick search didn’t reveal any useful XML parsing library compatible with Linux.</blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">Any suggestions?</blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">-g.</blockquote><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" data-mce-href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" data-mce-href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></span></div></div></blockquote></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-users mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-users@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-users@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></div></blockquote></div><br class=""></div></body></html>