<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=""><div><blockquote type="cite" class=""><div class="">On Sep 14, 2016, at 9:43 AM, FĂ©lix Cloutier 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I'm trying to create a NSAttributedString from its HTML representation in Swift 3 (from the Xcode 8 GM build). However, this doesn't work:<div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">import Foundation</div><div class="">import AppKit</div><div class=""><br class=""></div><div class="">let html = "&lt;i&gt;hello world&lt;/i&gt;"</div><div class="">let data = html.data(using: .utf8, allowLossyConversion: true)!</div><div class="">let attributed = NSAttributedString(HTML: data, documentAttributes: nil)</div></blockquote><div class=""><br class=""></div><div class="">The error that I get in the REPL (which is essentially identical to the one I get in an Xcode project) is:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""></div><blockquote type="cite" class=""><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">error: ambiguous use of 'init(HTML:documentAttributes:)'</span></div><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">let str = NSAttributedString(HTML: data!, documentAttributes: nil)</span></div><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</span></div><div style="margin: 0px; line-height: normal; font-family: Consolas; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">found this candidate</span></div><div style="margin: 0px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">found this candidate</span></div></blockquote><div class=""><div class=""><br class="webkit-block-placeholder"></div><div class="">How should I do it? And perhaps more importantly, what's being done to allow me to figure it out myself?</div></div></div></div></div></blockquote><br class=""></div><div>I go to a more complex call until the issue goes away. Then file a bug. For me, adding options in fixed the issue.&nbsp;</div><div><br class=""></div><div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> attributed = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSAttributedString</span><span style="font-variant-ligatures: no-common-ligatures" class="">(html: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">data</span><span style="font-variant-ligatures: no-common-ligatures" class="">, options: [:], documentAttributes: </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div><br class=""></div><div>Swift seems to struggle with these because without "options", the API could match either one.</div><div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo; min-height: 19px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">?(html data: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Data</span><span style="font-variant-ligatures: no-common-ligatures" class="">, documentAttributes dict: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">AutoreleasingUnsafeMutablePointer</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSDictionary</span><span style="font-variant-ligatures: no-common-ligatures" class="">?&gt;?)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo; min-height: 19px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">public</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">init</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?(html data: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Data</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, options: [</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">AnyHashable</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">Any</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] = [:], documentAttributes dict: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">AutoreleasingUnsafeMutablePointer</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">NSDictionary</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?&gt;?)</span></div></div><div><br class=""></div><div>-- E</div><br class=""></body></html>