Why SVProgressHUD throwing eorrr?

470 Views Asked by At

I am trying to integrate the SVProgressHUD library and want to show before the API response on my controller for that I have written a code but it's throwing an error like Thread 1: "-[MYOWEB.AppDelegate window]: unrecognized selector sent to instance 0x600001bc2a40"

//ViewController.swift

import UIKit
import SVProgressHUD
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        SVProgressHUD.setDefaultMaskType(.clear)
        SVProgressHUD.setDefaultStyle(.custom)
        SVProgressHUD.setForegroundColor(UIColor.white)
        SVProgressHUD.setBackgroundColor(#colorLiteral(red: 0.1333333333, green: 0.3764705882, blue: 0.9960784314, alpha: 1).withAlphaComponent(1))
    }


}
2

There are 2 best solutions below

0
On

My guess is that your AppDelegate.swift does not have a window property. i.e ‘let window; UIWindow’ The library depend on it see line 72 here https://github.com/SVProgressHUD/SVProgressHUD/blob/master/SVProgressHUD/SVProgressHUD.m

Look at the example demo app for more details https://github.com/SVProgressHUD/SVProgressHUD/blob/master/Demo/Classes/AppDelegate.h

2
On

I think the framework didn't adapt to the separation between scene, and app delegates yet. You still need to explicitly add a window property in AppDelegate as @cloudBalancing said.

A proposed workaround

1.Add window property in AppDelegate

var window: UIWindow?

2.Add below code at scene(_:willConnectTo:options)method in SceneDelegate

let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.window = self.window