How to use built-in Core Image filters the easy way

Maybe this is common knowledge and everybody knows this, but I’ve only recently come to learn how this works, so I thought I’d share.

I’ve been setting up Core Image filters like this for god knows how long:

The downsides are obvious:
1) I have to know the exact name of the filter (“CIColorPosterize”)
2) I have to know the keys and values it accepts (“inputLevels”)

    Browsing the Core Image headers, I did find functions for these filters where you could just call let filter = CIFilter.colorPosterize()

    Yet every time I tried, it never worked and would give me an error that
    CIFilter has no member 'colorPosterize'.
    Well, “Crap!“, I thought, this must be something that will become available eventually.

    How wrong I was. This has been available for a while, you just need to know how to do it!
    The “trick” is to not only import CoreImage, but also (why!?) import CoreImage.CIFilterBuiltins:

    And lo and behold, it works. I’m so happy, I could cry.
    I’m off to refactor some stuff now.


    Comments are closed.