B
B
bagos2014-12-08 16:43:36
Swift
bagos, 2014-12-08 16:43:36

Is it possible to change (set) the value of a variable in a delegate function in Swift?

Good afternoon!
It is required to parse the xml file received after authorization on the server, then get one value and pass it to the label.
As an NSXMLParser parser, in the body of the delegate function parser(_:foundCharacters:) I change the value of label.text to the one received in string. Is it possible to do so? Or should the output in the UI be done in some other way? The fact is that in the debugger I see that the value is received immediately, but on the form in the label it appears after 5 seconds, why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
An, 2014-12-09
@bagos

As far as I remember, NSXMLParser is not asynchronous, and if you call parse on the main thread, setting the label will work fine. But again, since it is asynchronous and you feed it fat xml, it hangs up the ui stream and therefore your label (and not only it, but all ui hangs) is updated after a while. You either need to run the parser asynchronously (see stackoverflow.com/questions/2862911/is-nsxmlparser... for examples) or use another, more convenient parser ( www.raywenderlich.com/553/xml-tutorial-for-ios-how. .. NSXMLParser has a damn inconvenient interface, as for me. In my projects, I personally use Google's. Oh yes, if you still decide to call the parser asynchronously - do not forget to return to the ui thread before setting the label

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question