WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Day 54 | Project 13 Challenge 1

Forums > 100 Days of Swift

Hi there,

I have completed challenges 2 & 3, but do not understand what I need to add/edit to the code to get an error to show when the save button is without an image...

I also don't know how to add images... of the code that i've tried. But, I've tried converting the guard let image = imageView.image into a if let and calling the image func withing that with an error, but it doesn't work.

Can anyone help me :')

PS. I've got no clue how to add images to this


What you want to do is keep the guard let image = imageView.image but change the else clause to display an error before it returns.

You can take a look at the image(_:didFinishSavingWithError:contextInfo:) function for an example you already have of how to show an error message to the user.

As for posting images here, you have to have them hosted somewhere, such as Dropbox or Imgur or whatever, and then put the URL in some markdown like this:

![description of the image](url of the image)

(Note that with Dropbox, you have to change the end of the URL from dl=0 to raw=1 in order for the image to display inlie rather than be a link to click. I'm not sure if there are any changes needed for Imgur URLs.)


Thank you for the advice @roosterboy!

Again I thought about doing that, and calling the image function inside the else of the guard let, I presumed that what the challenge was asking us to do is to invoke the first alertController in the image func as it's saying if let error = error { ....

How/What do I need to call the image function in the guard let ... else { to use that first AC. Or should I just be creating a 3rd alertController?


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.