Adapter Pattern in Swift for Beginners

“It is not the strongest of the species that survives, nor the most intelligent. It is the one that is most adaptable to change.”

-Charles Darwin

Image by Jono Dry on Jono Dry Art
Adapter Pattern Class Diagram
  1. An object that uses an adapter is the one that conforms to the adapter protocol.
  2. The adapter protocol is the one that dictates what the new code should use to adapt to the legacy class.
  3. An adaptor is developed to pass arguments and calls to the legacy object.
  4. A legacy class that existed prior to the creation of the protocol and cannot be directly changed to adhere to it.

When do we use it?

US to EU outlet adapter (converter)



Moment of truth, let's test it out

Login successful.
Token: 64236324.375928.23934324

Be careful when…



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