0

I have a service class, AuthManager, that has a method in it as below:

public func logoutAuth(from viewController: UIViewController, completion:((_ result: Bool) -> Void)? = nil) {
        let logoutString = "\(self.oAuthBaseServerURL)/logout.jsp"
        // Present the Sign Off ViewController
        if let logoutURL = URL(string: logoutString) {
            let logoutController = SFSafariViewController(url: logoutURL)
            let logoutDelegate = SFSafariViewDelegate(completion: completion)
            logoutController.delegate = logoutDelegate
            viewController.present(logoutController, animated: true, completion: nil)
        }
    }

I call this service from an instance of it (singleton in a global state) in my view controller like this:

GlobalState.AUTHMANAGER().logoutAuth(from: self, completion: self.completeLogout)

However, I am getting this error:

 [Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFSafariViewController: 0x7ff9b1060800>)

I'm not sure why that is deallocating too early. I've tried making the SFSafariViewController an instance variable and assigning it in the method instead, which yields the same error.

steventnorris
  • 5,656
  • 23
  • 93
  • 174
  • Try including deinit in these classes and print a message or use breakpoints to see when they're getting deallocated. Seems like things aren't happening in the order you expect. – Ron May 02 '19 at 01:19
  • Show how you call this method and show where `viewController` comes from and its lifetime. Also note that the delegate will be gone immediately since there is no strong reference to it anywhere. – rmaddy May 02 '19 at 02:34
  • This ended up being an issue with Xcode 10 not properly handling local pod references as they changed, essentially not recompiling them properly but still accepting the code as changed somehow. It's a known issue in Xcode 10 with odd and unhelpful errors that don't indicate it being the problem. Took a long while to dig down and figure out what was going on here. – steventnorris May 03 '19 at 17:54

0 Answers0