swift dispatch after
let deadlineTime = DispatchTime.now() + .seconds(1)
DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
print("test")
}
swift dispatch after
let deadlineTime = DispatchTime.now() + .seconds(1)
DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
print("test")
}
DispatchGroup example swift
class DispatchGroupExample: UIViewController {
private let dispatchGroup = DispatchGroup()
override func viewDidLoad() {
super.viewDidLoad()
fetchData(url: xxx)
fetchData(url: yyy)
// 3: notify job done
dispatchGroup.notify(queue: .main) {
self.goToNext()
}
}
private func fetchData(url: URL) {
// 1: enter group
dispatchGroup.enter()
URLSession.shared.dataTask(with: url) {
[weak self] (data, urlResponse, error) in
// parse data
...
// 2: leave group
self?.dispatchGroup.leave()
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us