caipivara
4/22/2015 - 6:16 PM

iOS - AFNetworking extension - Cancel request with url, needs https://gist.github.com/danielgomezrico/ae53fae471168dde6c21

iOS - AFNetworking extension - Cancel request with url, needs https://gist.github.com/danielgomezrico/ae53fae471168dde6c21

extension AFHTTPRequestOperationManager {
    
    func cancelRequestWithUrl(url: String) {
        
        let operations = operationQueue.operations
        
        for operation in operations {
            if let afOperation = operation as? AFHTTPRequestOperation,
                operationUrl = afOperation.request.URL
                where operationUrl.isEquivalent(url) {
                    afOperation.cancel()
                    println("***Canceled")
                    break
            }
        }
        
    }
    
}