Quick tip: How to sort array of objects by given property in custom order in Swift?

Imagine this, you have a class and enum like:

and you want to sort users by their status, but users with error first. How to do that?

This is quite easy, just extend, or add custom property to UserDto like:

and now you can just use ordinary sort() or sorted():

Leave a Reply