         return AnimatedImage(data: data, poster: poster)
     }
     
+    /// Return true if the image data represents animated image in GIF format.
     public func isAnimatedGIFData(data: NSData) -> Bool {
         let sigLength = 3
         if data.length < sigLength {

import Nuke
import ImageIO

public class AnimatedImage: UIImage {
    public let data: NSData! // it's nonnull
    
    public init(data: NSData, poster: CGImageRef) {
        self.data = data
        super.init(CGImage: poster, scale: 1, orientation: .Up)
    }
    
    public required init?(coder decoder: NSCoder) {
        self.data = nil // makes me sad
        super.init(coder: decoder)
    }
    
    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 {
    public init() {}
    
    public func decode(data: NSData, response: NSURLResponse?) -> Image? {
        guard self.isAnimatedGIFData(data) else {
            return nil

    }
}

/// Prevents `ImageLoader` from processing animated images.
public class AnimatedImageLoaderDelegate: ImageLoaderDefaultDelegate {
    /// Disabled processing of animated images.
    public override func loader(loader: ImageLoader, processorFor request: ImageRequest, image: Image) -> ImageProcessing? {
        return image is AnimatedImage ? nil : super.loader(loader, processorFor: request, image: image)
    }
}

/// Memory cache that is aware of animated images. Can be used for both single-frame and animated images.
public class AnimatedImageMemoryCache: ImageMemoryCache {

    /// Can be used to disable storing animated images. Default value is true (storage is allowed).
    public var allowsAnimatedImagesStorage = true

    /// Stores response unless the image is an instance of AnimatedImage class and animated image storage is disabled.
    public override func setResponse(response: ImageCachedResponse, forKey key: ImageRequestKey) {
        if !self.allowsAnimatedImagesStorage && response.image is AnimatedImage {
            return
