I have the following code. It worked fine in Swift 2.3:
self.newsScrollView.contentSize = CGSize(width: self.newsScrollView.frame.size.width * CGFloat(topics.count), height: self.newsScrollView.frame.size.height)
for i in 0..<topics.count {
let frame = CGRect(x: CGFloat(i) * self.newsScrollView.frame.size.width, y: 0, width: self.newsScrollView.frame.size.width, height: self.newsScrollView.frame.size.height)
let topic = topics[i]
let newsView = TrendingTopicView(topic: topic, frame: frame)
newsView.delegate = self
self.newsScrollView.addSubview(newsView)
}
Now, I receive a warning in the debugger:
This application is modifying the autolayout engine from a background thread after
the engine was accessed from the main thread.
This can lead to engine corruption and weird crashes.
So, I tried editing it to this:
DispatchQueue.main.async {
self.newsScrollView.addSubview(newsView)
}
But I still receive the warning. I have also tried the DispatchQueue.main.async(execute:) as well. What am I doing wrong? If I'm not mistaken, the DispatchQueue.main.async inSwift 3 is the equivalent of dispatch_async(dispatch_get_main_queue) in Swift 2.x right?
Any help is appreciated. Thanks