Exploiting enums in Swift is very useful and can be used in many ways
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way. Enumerations are first-class types, so they adopt many features supported by classes.
They can also :
Like other types in Swift, their names start with a capital letter. Give enumeration types singular rather than plural names, so that they read as self-evident.
Here is an example…
Tutorial made with Swift 5
Repeat code, waste time, fail probability
Who hasn’t repeat some lines of code to set the label font or the label color, or to change the color of a button in dependence of it if is enabled or disabled ? I think almost everyone who works in programming.
This example may seem like it’s not that bad but if your app has a lot of screens it becomes a problem. And imagine that you have to change the font for every label because the app is suffering a design change. You will waste a…
Tutorial made with Xcode 10.3 and Swift 5.0
One of the best practices in programming is reusing as max as you can.
If you have more than one screen (UIViewController, xib…) with the same visual element (UIView, UIButton…) you should consider making one generic element instead of copy-paste one time and one more time and one more time….
This solution saves you time to future implementations. And if you need to make a change you have to change it just once.
Create a New file → Cocoa Touch Class → Give the name you want to your class view. Subclass…