         }
         
     }
+}
+
+class Block<T> {
+    let f : T
+    init (_ f: T) { self.f = f }
+}
+
+private var apng_userInfoKey: Void?
+extension CADisplayLink {
+    
+    public var apng_userInfo: AnyObject? {
+        get {
+            return objc_getAssociatedObject(self, &apng_userInfoKey)
+        }
+    }
+    
+    private func apng_setUserInfo(userInfo: AnyObject?) {
+        objc_setAssociatedObject(self, &apng_userInfoKey, userInfo, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+    }
+    
+    static func apng_displayLink(block: (CADisplayLink) -> ()) -> CADisplayLink
+    {
+        let displayLink = CADisplayLink(target: self, selector: "apng_blockInvoke:")
+        
+        let block = Block(block)
+        displayLink.apng_setUserInfo(block)
+        return displayLink
+    }
+    
+    static func apng_blockInvoke(sender: CADisplayLink) {
+        if let block = sender.apng_userInfo as? Block<(CADisplayLink)->()> {
+            block.f(sender)
+        }
+    }
+    
 }
        }
        
        isAnimating = true
        timer = CADisplayLink(target: self, selector: "tick:")
        timer?.addToRunLoop(mainRunLoop, forMode: NSDefaultRunLoopMode)
    }
    

    deinit {
        stopAnimating()
    }

    /**
    Initialize an APNG image view with a decoder.
