Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift dispatch queue

extension DispatchQueue {

    static func background(delay: Double = 0.0, background: (()->Void)? = nil, completion: (() -> Void)? = nil) {
        DispatchQueue.global(qos: .background).async {
            background?()
            if let completion = completion {
                DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: {
                    completion()
                })
            }
        }
    }

}

DispatchQueue.background(delay: 3.0, background: {
    // do something in background
}, completion: {
    // when background job finishes, wait 3 seconds and do something in main thread
})

DispatchQueue.background(background: {
    // do something in background
}, completion:{
    // when background job finished, do something in main thread
})

DispatchQueue.background(delay: 3.0, completion:{
    // do something in main thread after 3 seconds
})
Comment

PREVIOUS NEXT
Code Example
Swift :: swift collection view check if you are at the bottom 
Swift :: swift qrcode scanner 
Swift :: button color swiftui 
Swift :: how to change background color of ui button swift 
Swift :: and in swift4 
Swift :: clone repo using jenkins pipeline 
Swift :: react native ios rtl 
Swift :: ios swift create new background thread 
Swift :: How to find index of list item in Swift? 
Swift :: string index in swift 
Swift :: change font swiftui 
Swift :: count down timer swift stack overflow 
Swift :: how to add an underline to a textField swift 
Swift :: uilabel make bold 
Swift :: average in array swift 
Swift :: turning an arrya into a set swift 
Swift :: swift add navigation bar 
Swift :: uitableview bottom inset 
Swift :: swift 5 change message color of alert 
Swift :: uikit call swiftui view 
Swift :: Swift Variable names cannot start with numbers 
Swift :: swift session.input 
Swift :: UINavigationBar turns black 
Swift :: Swift Array With Mixed Data Types 
Swift :: separator style swiftui list 
Swift :: Initializer Swift 
Swift :: change multiplier programactlilly ios swift 
Swift :: Alamofire upload multiple image with parameters swift 5 site:stackoverflow.com 
Swift :: xamarin get textview by id 
Swift :: Swift continue Statement With for Loop 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =