When creating views in SwiftUI you will almost certainly use View Modifiers to adjust how a view looks from its font, to border, to colours, and so on. It is not uncommon to have serveral modifiers applied to each item in the view to get the look that you desire.
SwiftUI provides a way to group these modifiers together so that you can apply them as a group. There are a few benefits to this:
First, it cleans up the code in your view because you can have just a single custom modifier applied and keep all of the details encapsulated elsewhere in the code.
Second, it allows you to reuse the same group of modifiers elsewhere in the app so that you can keep your code DRY (don’t repeat yourself). A change in the custom modifier would affect all views that use the custom modifier.
In this tutorial we’ll look at how we can create our own custom modifier and how this can be applied to a view.
[Read more…]