Step 2— Register For Previewing ✅

In order to implement Peek & Pop we need to call a method called registerForPreviewing(with:sourceView:). Directly quoting from the Apple Docs article Implementing Peek and Pop:

Call registerForPreviewing(with:sourceView:) to register a class which implements the UIViewControllerPreviewingDelegate protocol, and then pass in a view which responds to the 3D Touch.

This method will let us use or in other words register, a view to present from, within our ViewController that implements the required methods for Peek and Pop which come from the UIViewControllerPreviewingDelegate.

If that doesn’t make sense, just keep reading and write the exact code I do, and it will eventually click in your head after a few runs.

put this in your view controller.

Step 3— Utilize the required UIViewControllerPreviewingDelegate Protocol methods. ✅

Have your ViewController adopt the UIViewControllerPreviewingDelegate Swift protocol like so. You’ll get a nasty error.