No idea what is happening here since I've followed other answers that use this including Swift: synchronously perform code in background; queue.sync does not work as I would expect
I have an XMLParser that I need to load 2 RSS feeds. To prevent reentrant parsing, I need to load these URLs one after the other is done. Problem is I need to do this in the background/async so it doesn't freeze up the UI.
I have this:
var myParser: XMLParser = XMLParser()
let parseQueue = DispatchQueue(label: "xmlQueue", attributes: [], target: nil)
var feeds = [RSS_FEED_URL_COT, RSS_FEED_URL] //this order
self.parseQueue.async {
for f in feeds
{
self.loadRSSData(rssFeed: f)
}
}
This does work meaning no reentrant error, but for a good 30 seconds whole UI is frozen up. What am I doing wrong here?
EDIT:
func loadRSSData(rssFeed: String){
if let rssURL = URL(string: rssFeed) {
print("LOADING THE URL: ", rssURL)
// fetch rss content from url
if let contents = XMLParser(contentsOf: rssURL)
{
self.myParser = contents
}
// set parser delegate
self.myParser.delegate = self
self.myParser.shouldResolveExternalEntities = false
// start parsing
self.myParser.parse()
}
}