-2

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))
    }


}
Kamal Fach
  • 79
  • 6

2 Answers2

0

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

CloudBalancing
  • 1,461
  • 2
  • 11
  • 22
0

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
MadawiAh
  • 27
  • 3
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – 4b0 Sep 08 '22 at 07:46
  • Thank you for the advice @4b0 . if you have any further comments, please share them. – MadawiAh Sep 08 '22 at 08:23