I'm trying to create an NSXMLNode using Swift. This seems like it should be pretty straightforward based on the class reference (and Xcode's autocompletion):
var anAttribute: NSXMLNode = NSXMLNode.attributeWithName("name", stringValue: "string")
But I get an error: "Missing argument for parameter 'URI' in call."
I then try:
var anAttribute: NSXMLNode = NSXMLNode.attributeWithName("name", URI: "uri", stringValue: "string")
Which produces the equally beguiling error: "Extra argument 'URI' in call."
Can anyone tell me what's going on here?
attributeWithName()returnsAnyObject?, the Swift mapping ofid. Therefore you have to cast the return value to the expected type:or, if you want to check for a possible failure:
The underlying reason is that the Objective-C function
returns
id. If it were declared as(which is the "modern" way to declare class/factory methods) then this would be mapped to Swift as
making the explicit cast unnecessary. You could file a bug report to Apple about that.