Understand how to work with threads in Swift, found an example that looks like this
private func searchForTweets() { if let request = twitterRequest { request.fetchTweets { [weak self] newTweets in if let wSelf = self { dispatch_async(dispatch_get_main_queue()) { if !newTweets.isEmpty { tweets.insert(newTweets, at: 0) } } } } } } But in swift 3 , Dispatch was changed and I can’t find a normal tutorial (advise if you have it at hand. I didn’t find it in off-docks either)
So as I understood, I did it like this
private func searchForTweets() { if let request = twitterRequest { request.fetchTweets { [weak self] newTweets in if let wSelf = self { DispatchQueue.global().async { if !newTweets.isEmpty { wSelf.tweets.insert(newTweets, at: 0) } } } } But I'm not sure that this is correct. I’m confused by the fact that in the example they are passed as the parameter dispatch_get_main_queue() , and I don’t pass anything on myself ...