dannyYassine / DownloadOperationQueue

NSOperationQueue subclass fires a completionBlock when all operations are finished.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DownloadOperationQueue

NSOperationQueue subclass fires a completionBlock when all operations are finished.

Using KVO, we observe the "operations" keypath. When it hits zero, it fires the completionBlock?()

    let operationQueue = DownloadOperationQueue()
    
    let blockOperation1 = NSBlockOperation { 
        // Do Stuff
    }
    
    // Custom NSOperation
    let downloadOperation1 = DowloadImageOperation(stringURL: imageURLs[0], delegate: self)

    
    // Set your completion block
    self.operationQueue.completionBlock = {
        print("All finished!")
    }

    operationQueue.addOperations([blockOperation1, downloadOperation1], waitUntilFinished: false)

About

NSOperationQueue subclass fires a completionBlock when all operations are finished.

License:MIT License


Languages

Language:Swift 100.0%