I am trying to create objects dynamically based on the output of an XML file. My apologies if there are other posts on this subject, I don't even know what this is called. Basically I want to create a stack of objects that could be of any class. In a nutshell, when the "didStartElement" of the NSXMLParser is called, I want to create an object of type "elementName" and stack it to my object stack. The code below is not working, just trying to illustrate what I am trying to accomplish. Normally I would just put "objectStack.append(object) as object" but in this case I don't know what the object type is going to be until the element is scanned by the XML parser. I believe the NSClassFromString is the way to do this, but it's not working.
func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
objectStack.append(NSClassFromString(elementName))
}
Any assistance would be greatly appreciated. Even if you can just point me in the right direction.
objectStack.append(NSClassFromString(elementName)())note the extra().