Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

ios swift create new background thread

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()
                })
            }
        }
    }
}

// USAGE 

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 :: convert string to unit swift 
Swift :: swift string to dictionary 
Swift :: swift uitableview insert cell 
Swift :: struct to json convert in swift 
Swift :: Module compiled with Swift 5.3 cannot be imported by the Swift 5.3.1 compiler 
Swift :: custom tab bar swift ios 
Swift :: swift guard let 
Swift :: check if string in array of string swift 
Swift :: enviroment dissmiss swiftui 
Swift :: swift 5 get app version 
Swift :: uilabel make bold 
Swift :: change ui button swift 
Swift :: swiftui font add 
Swift :: button click programmatically swift 
Swift :: swift get file size from url 
Swift :: swift extension Array of element 
Swift :: swift how to set warning message 
Swift :: swift switch 
Swift :: two variable sum 
Swift :: Swift Omit Argument Labels 
Swift :: Create a Tuple 
Swift :: free robux codes 
Swift :: parsing to double any data type in swift 
Swift :: Create a Throwing Function Swift 
Swift :: function parameters swift 
Swift :: uilabel font size and bold 
Swift :: swift connect wifi 
Swift :: Example: Nested Tuple 
Swift :: Adapt sfsymbol to frame swiftui 
Ruby :: How to find database name in rails console 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =