Using Swift/cocoa I am creating a user input form that will output an XML file. (Beginner to all the above.)
The user will be adding multiple targets but I am getting an error when trying to create multiple 'targets.'
The flow is: User enters the number of targets they want to create (7,8. or 9). Each target has information that the user enters, so there are 'x' number of targets. I use a for loop but am getting an error when trying to create the next target. Below is my code from the playground.
(If I uncomment //expedition.addChild(target) I receive an error.)
How do I create these multiple target children?
let root = NSXMLElement(name: "exploration_game")
let xmlFile = NSXMLDocument (rootElement: root)
let expedition = NSXMLElement(name: "expedition")
root.addChild(expedition)
expedition.addChild(NSXMLElement(name: "name", stringValue: ""))
expedition.addChild(NSXMLElement(name: "targets", stringValue: ""))
expedition.addChild(NSXMLElement(name: "difficulty", stringValue: ""))
expedition.addChild(NSXMLElement(name: "factoid", stringValue: ""))
expedition.addChild(NSXMLElement(name: "factoid_file", stringValue: ""))
let target = NSXMLElement(name: "target")
expedition.addChild(target)
for index in 1...3{
//expedition.addChild(target)
target.addChild(NSXMLElement(name: "target_title_en", stringValue: ""))
target.addChild(NSXMLElement(name: "target_title_sp", stringValue: ""))
target.addChild(NSXMLElement(name: "target_hint_en", stringValue: ""))
target.addChild(NSXMLElement(name: "target_hint_sp", stringValue: ""))
target.addChild(NSXMLElement(name: "target_description_en", stringValue: ""))
target.addChild(NSXMLElement(name: "target_descriptionsp", stringValue: ""))
target.addChild(NSXMLElement(name: "x", stringValue: ""))
target.addChild(NSXMLElement(name: "y", stringValue: ""))
target.addChild(NSXMLElement(name: "target_icon", stringValue: ""))
target.addChild(NSXMLElement(name: "target_somethin", stringValue: ""))
}
Help is much appreciated.
No comments:
Post a Comment