UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Project 13, part two: Selecting the GaussianBlue filter crashes the app

Forums > 100 Days of Swift

Hey everyone!

Here is the code that xcode says is crashing the app:

func setFilter(action: UIAlertAction) {
        // make sure we have a valid image before continuing!
        guard currentImage != nil else { return }

        // safely read the alert action's title
        guard let actionTitle = action.title else { return }

        currentFilter = CIFilter(name: actionTitle)

        let beginImage = CIImage(image: currentImage)
        currentFilter.setValue(beginImage, forKey: kCIInputImageKey)

        applyProcessing()
    }

(👆🏼 I literally copied/pasta that code from the tutorial just to make sure it wasn't a typo. )

Specifically, xcode is pointing to currentFilter.setValue(beginImage, forKey: kCIInputImageKey) claiming that it's a Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

I'm assuming that it's referring to the beginImage constant but, it works fine with all of the other filters.

I've tried safely unwrapping it with guard let and if let but no luck.

I haven't been able to find out why this happens, and why it's only with the GaussianBlue filter. Any help would be much appreciated.

See my repo here.

Thank you!

3      

It's because there is no GaussianBlue filter; it's GaussianBlur. So when you try to create a filter using that title, it comes out nil.

4      

🤦🏻‍

Thank you @roosterboy

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.