How to limit a variable in Swift
No Clamping in the Swift Standard Library?!
Over the years, I’ve had a few instances where I needed to limit the potential of a variable. For instance, maybe I have a shopping app and I need to limit the maximum price of any given item. You may be surprised to learn that there’s no built-in way to tackle this in the Swift Standard Library. There are many solutions, but most come with glaring caveats.