in my app I want to set the text of an UILabel
. The text comes from a JSON-object. I add my UILabel
to my storyboard, set the IBOutlet
and
c_rath's answer is correct. In swift 3 the syntax was changed (yet again) to
DispatchQueue.main.async {
self. label_news?.text = resp.NewsText
}
Like what Rob stated in the comment, all UI changes need to be done on the main thread. I haven't implemented it in Swift yet, but the Objective-C and what I'm assuming would be the Swift is below...
Objective-C
dispatch_async(dispatch_get_main_queue(), ^{
self.label_news.text = resp.NewsText;
});
Swift:
dispatch_async(dispatch_get_main_queue()) {
self.label_news.text = resp.NewsText;
}