Here we have a singleton object to handle all of the notification logic in our app.

In this class, we have a new scheduleNotification method that is mostly the same as the one we wrote before in ViewController.swift , but with logic to handle attachments.

There’s also a method for handling the attachment images for our notifications. This function returns a Promise and takes the Giphy URL. It then downloads the image and saves it to a file. That file URL gets passed to the next function in the chain.

The createNotification method is what we will call from ViewController.swift whenever the button in the app is pressed. This will kick off the call chain that will grab an image from Giphy, prepare it to be placed as an attachment in a notification, and then schedule that notification to be sent.

Now head back over to ViewController.swift and remove the code we wrote before: both the scheduleNotification function and the let notificationIdentifier = "myNotification" line at the top of the class.