         super.setResponse(response, forKey: key)
     }
 
+    /// Returns cost for a given image.
     public override func costFor(image: Image) -> Int {
         if let animatedImage = image as? AnimatedImage {
             return animatedImage.data.length + super.costFor(image)

        return AnimatedImage(data: data, poster: poster)
    }
    
    public func isAnimatedGIFData(data: NSData) -> Bool {
        let sigLength = 3
        if data.length < sigLength {

import Nuke
import ImageIO

/// Represents animated image.
public class AnimatedImage: UIImage {
    /// Image data that the receiver was initialized with.
    public let data: NSData! // it's nonnull
    
    /// Initializes the receiver with a given data and poster image.
    public init(data: NSData, poster: CGImageRef) {
        self.data = data
        super.init(CGImage: poster, scale: 1, orientation: .Up)
    }
    
    /// Not implemented.
    public required init?(coder decoder: NSCoder) {
        self.data = nil // makes me sad
        super.init(coder: decoder)
    }
    
    /// Not implemented.
    public required convenience init(imageLiteral name: String) {
        fatalError("init(imageLiteral:) has not been implemented")
    }
}

/// Creates instances of `AnimatedImage` class from the given data. Checks if the image data is in a GIF image format, otherwise returns nil.
public class AnimatedImageDecoder: ImageDecoding {
    /// Initializer the receiver.
    public init() {}
    
    /// Decodes image data and returns an instance of AnimatedImage class.
    public func decode(data: NSData, response: NSURLResponse?) -> Image? {
        guard self.isAnimatedGIFData(data) else {
            return nil
