             return task as? WTURLSessionTask
         }
         set{
-            let task = objc_getAssociatedObject(self, &WTUIButtonImageDownloadTaskKey)
-            if task != nil {
-                if task is URLSessionDataTask {
+            if let task = objc_getAssociatedObject(self, &WTUIButtonImageDownloadTaskKey){
+                if task is WTURLSessionTask {
                     let myTask:WTURLSessionTask = task as! WTURLSessionTask
                     myTask.cancel()
                 }

        set{
            let task = objc_getAssociatedObject(self, &WTUIImageViewImageDataTaskKey)
            if task != nil {
                if task is URLSessionDataTask {
                    let myTask:WTURLSessionTask = task as! WTURLSessionTask
                    myTask.cancel()
                }

    public class func cachedImageDataTask(with url:String,completionHandler:@escaping (UIImage?,Error?)->Void)->WTURLSessionTask{
        let task = dataTask(with: url)
        task.cacheTime = -1
        
        task.imageHandler = {(image,error) in
            completionHandler(image,error)
        }
        return task
    }
