Swift: Getting 'Snapshotting a view that has not been rendered..' error when trying to open a URL in safari from my app

It might not be the same problem as me, but I just solved the same warning in my logs.

I'm showing a UIAlertController as an actionSheet popover on an iPad, and I had exactly the same warning 8 times in a row every time I tried to show the alert controller.

To make the warning disappear all I had to do was to layout the alert controller view as in the following code:

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)

    ...            

alertController.view.layoutIfNeeded() //avoid Snapshotting error
self.presentViewController(alertController, animated: true, completion: nil)

I hope this helps you or any other person having the same warning.


Also using Objective-C, using the suggested [modeAlert.view layoutIfNeeded] reduced errors to one as above. Final error has been suppressed by changing last addAction from UIAlertActionStyleCancel to UIAlertActionStyleDefault as below. Not a great workaround to what appears to be a bug.

[modeAlert addAction:[UIAlertAction
                  actionWithTitle:NSLocalizedString(@"Cancel", @"")
                  style:UIAlertActionStyleDefault
                  handler:nil ]];

To avoid copy/paste from Saliom's answer you can make such subclass and use it instead of UIAlertController:

class AlertController: UIAlertController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.view.layoutIfNeeded()
    }

}