Chapter 4 - Challenge Solution (Please help me understand)

In the given solution

func alert(title: String, text: String?) -> Observable<Void> {
    return Observable.create { [weak self] observer in
        let alertVC = UIAlertController(title: title, message: text, preferredStyle: .alert)
        
        alertVC.addAction(UIAlertAction(title: "Close", style: .default, handler: {_ in
            observer.onCompleted()
        }))
        
        self?.present(alertVC, animated: true, completion: nil)
        
        return Disposables.create {
            self?.dismiss(animated: true, completion: nil)
        }
    }
}

why are we calling dismiss method on self in Disposables.create? Isn’t self the UIViewController itself?

From apple’s docs on dismiss(animated:completion) “Dismisses the view controller that was presented modally by the view controller.”

Thank you :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.