La meilleure pratique consiste à définir une fonction réutilisable accessible plusieurs fois.
FONCTION RÉUTILISABLE:
par exemple quelque part comme AppDelegate.swift en tant que fonction globale.
func backgroundThread(_ delay: Double = 0.0, background: (() -> Void)? = nil, completion: (() -> Void)? = nil) {
    dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.value), 0)) {
        background?()
        let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)))
        dispatch_after(popTime, dispatch_get_main_queue()) {
            completion?()
        }
    }
}
Remarque: dans Swift 2.0, remplacez QOS_CLASS_USER_INITIATED.value ci-dessus par QOS_CLASS_USER_INITIATED.rawValue à la place
USAGE:
A. Pour exécuter un processus en arrière-plan avec un délai de 3 secondes:
    backgroundThread(3.0, background: {
            // Your background function here
    })
B. Pour exécuter un processus en arrière-plan, puis exécutez une complétion au premier plan:
    backgroundThread(background: {
            // Your function here to run in the background
    },
    completion: {
            // A function to run in the foreground when the background thread is complete
    })
C. Pour retarder de 3 secondes - notez l'utilisation du paramètre d'achèvement sans paramètre d'arrière-plan:
    backgroundThread(3.0, completion: {
            // Your delayed function here to be run in the foreground
    })