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

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



public extension UIImage {
    /// Automatically detect and load the image from local or a remote url.
    public class func remoteOrLocalImage(_ named: String, bundle: Bundle? = nil, callback: @escaping (_ image: UIImage?) -> Void) {
        guard !named.isBlank else {
            callback?(nil)
            return
        }

        if let url = URL(string: named), url.host != nil {
            SDWebImageDownloader.shared().downloadImage(with: url, options: [],
                progress: { receivedSize, expectedSize in

                },
                completed: { image, data, error, finished in
                    guard let image = image, finished else {
                        dispatch.async.main {
                            callback(nil)
                        }
                        return
                    }
                    dispatch.async.main {
                        callback(image)
                    }
