             }
         } else {
             dispatch.async.bg(.userInitiated) {[weak self] in
-                guard let weakSelf = self, let image = UIImage(named: named) else { return }
+                guard let weakSelf = self, let image = UIImage(named: named) else {
+                    dispatch.async.main {
+                        callback?(nil)
+                    }
+                    return
+                }
+
                 dispatch.async.main {
                     defer { callback?(image) }
 

            )
        } else {
            dispatch.async.bg(.userInitiated) {
                guard let image = UIImage(named: named, in: bundle, compatibleWith: nil) else { return }
                dispatch.async.main {
                    callback(image)
                }


public extension UIImageView {
    /// Automatically detect and load the image from local or a remote url.
    public func remoteOrLocalImage(_ named: String, alwaysAnimate: Bool = false, animationDuration: TimeInterval = 0.5, callback: ((_ image: UIImage?) -> Void)? = nil) {
        guard !named.isBlank else {
            image = nil
            callback?(nil)
            return
        }

        if let url = URL(string: named), url.host != nil {
            self.sd_setImage(with: url) {[weak self] (image, _, cacheType, _) in
                guard let image = image else {
                    dispatch.async.main {
                        callback?(nil)
                    }
                    return
                }

                defer {
                    dispatch.async.main {
                        callback?(image)
                    }
                }

                if let weakSelf = self, (alwaysAnimate || cacheType != SDImageCacheType.memory) {
                    weakSelf.alpha = 0
                    UIView.animate(withDuration: animationDuration) {
