`XMLDocument.xmlData(withOptions:)` can't be compiled with Swift 3

Number:rdar://31671195 Date Originated:18-Apr-2017 09:55 AM
Status:Open Resolved:
Product:Developer Tools Product Version:8.3.1 (8E1000a)
Classification:Other Bug Reproducible:Always
憲男 野村18-Apr-2017 09:55 AM

Swift compiler complain
> error: cannot call value of non-function type 'Data’
on using `XMLDocument.xmlData(withOptions:)`

Steps to Reproduce:
1. Paste following codes to Playground:
import Foundation

let document = try XMLDocument(xmlString: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
                               options: Int(XMLNode.Options.documentTidyXML.rawValue))
// build error with "error: cannot call value of non-function type 'Data'"
let data1 = document.xmlData(withOptions: XMLNode.Options.nodePrettyPrint.rawValue)

Expected Results:
2. compiled

Actual Results:
2. got “error: cannot call value of non-function type 'Data”

Xcode 8.3.1 (8E1000a)

It needs workaround…:
// work around…
let selector = #selector(XMLDocument.xmlData(withOptions:))
let object = XMLNode.Options.nodePrettyPrint.rawValue
let data3 = document.perform(selector, with: object).takeRetainedValue() as! Data

Swift 3.0.2
Swift 3.1

'MacBook Pro (Retina, 13-inch, Late 2013) w: macOS 10.12.4 (16E195).spx' was successfully uploaded.


Apple Developer Relations20-Apr-2017 08:40 AM

This very poor error message is caused by a type error: xmlData(withOptions:) expects an Int, but XMLNode.Options.nodePrettyPrint.rawValue is a UInt. A better workaround is using the one used in the XMLDocument constructor: cast the rawValue to the right type, like document.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint.rawValue)).

By Norio.Nomura at April 19, 2017, 11:46 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!