                 return
             }
             
+            uSelf.downloadReceipts.removeObject(forKey: photo)
             photo.image = image
             uSelf.delegate?.networkIntegration(uSelf, loadDidFinishWith: photo)
         }


import AFNetworking

public class AFNetworkingIntegration: NSObject, NetworkIntegration {
    
    weak public var delegate: NetworkIntegrationDelegate?
    
    public func loadPhoto(_ photo: Photo) {
        if photo.imageData != nil || photo.image != nil {
            self.delegate?.networkIntegration(self, loadDidFinishWith: photo)
        }

                return
            }
            
            uSelf.downloadReceipts.removeObject(forKey: photo)
            uSelf.delegate?.networkIntegration(uSelf, loadDidFailWith: error, for: photo)
        }
        
        let urlRequest = URLRequest(url: url)
        guard let receipt = AFImageDownloader.defaultInstance().downloadImage(for: urlRequest, success: success, failure: failure) else {
            return
        }
        
        self.downloadReceipts.setObject(receipt, forKey: photo)
    }
    
    func cancelLoad(for photo: PhotoProtocol) {
        guard let receipt = self.downloadReceipts.object(forKey: photo) else {
            return
        }
        
        AFImageDownloader.defaultInstance().cancelTask(for: receipt)
        self.downloadReceipts.removeObject(forKey: photo)
    }
    
    func cancelAllLoads() {
        let enumerator = self.downloadReceipts.objectEnumerator()
        
        while let receipt = enumerator?.nextObject() as? AFImageDownloadReceipt {
            AFImageDownloader.defaultInstance().cancelTask(for: receipt)
        }
        
        self.downloadReceipts.removeAllObjects()
    }
    
}
