我能够从SOAP获得响应,也可以在当前的viewController中打印,但我想将此响应传递给secondViewController。我尝试过简单的传递方法,但它不起作用。
func connectionDidFinishLoading(connection: NSURLConnection!) {
print(mutableData)
let xmlParser = XMLParser(data: mutableData as Data)
xmlParser.delegate = self
xmlParser.shouldProcessNamespaces = false
xmlParser.shouldReportNamespacePrefixes = false
xmlParser.shouldResolveExternalEntities = false
xmlParser.parse()
}
// Operation to do when a new element is parsed
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
lastElementName = currentElementName
currentElementName = elementName as NSString
if(elementName == firstNodeName){
elements = NSMutableDictionary()
elements = [:]
operation = NSMutableString()
operation = ""
message = NSMutableString()
message = ""
status = NSMutableString()
status = ""
}
}
// Operations to do for each element
func parser(_ parser: XMLParser, foundCharacters string: String) {
// print(String(format : "foundCharacters / value %@", string))
if currentElementName == "message" {
message.append(string)
print(message) //I can print this response in my current ViewController But i cant pass this response to my secondViewController
}
if currentElementName == "status" {
status.append(string)
print(status)
}
}
答案 0 :(得分:0)
let responce = NSString(data: mutableData as Data, encoding: String.Encoding.utf8.rawValue)
尝试将可变数据转换为NSString,然后将数据作为String传递给另一个UIViewController。