Hi all, please help!
Swift 3, this builds:
let xdat: NSData = xDoc.xmlData as NSDataThis does not:
let xdat: NSData = xDoc.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint)) as NSDataMy error is:
/Proj/.../ConfigManager.swift:55:35: error: cannot call value of non-function type 'Data'
let xdat: NSData = xDoc.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint)) as NSData
~~~~~~~~~~~~^Of course one is a property and the other is a method. Both return type Data:
https://developer.apple.com/reference/foundation/xmldocument#1770347
Anyone have any ideas why I can't get ".xmlData(withOptions:)" to compile? Calling just ".xmlData" builds & runs fine, but generates XML packed onto one line. The XML I write absolutely has to be human-readable/editable!
Thanks for any assistance,
Tadd
Try this:
let xdat: NSData = xDoc.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint.rawValue)) as NSData`XMLNode.Options.nodePrettyPrint` is an enum, which cannot be converted to Int with initializer. You need to convert its rawValue (:UInt) to Int.
And when you have any number of type related errors as such, Swift does not generate a good diagnostics for methods overloaded with properties.
By the way, why don't you make your `xdat` as `Data`? As Swift 3 imports almost all `NSData` in the Cocoa APIs as `Data`, you can work better with them, using `Data` as far as you can.
let xdat: Data = xDoc.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint.rawValue))