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 :

  • Define initializers to provide an initial value
  • Be extended to expand their functionality
  • Conform to protocols

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.

Simple enumeration example

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.

Problem Example :

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

Why should we reuse UIViews?

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.

Example of a reusable view

Step 1: Create the class of reusable view

Create a New file → Cocoa Touch Class → Give the name you want to your class view. Subclass…

Pablo Blanco

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store