🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »

Adapter in Swift

Adapter is a structural design pattern, which allows incompatible objects to collaborate.

The Adapter acts as a wrapper between two objects. It catches calls for one object and transforms them to format and interface recognizable by the second object.

Learn more about Adapter

Usage of the pattern in Swift



Usage examples: The Adapter pattern is pretty common in Swift code. It’s very often used in systems based on some legacy code. In such cases, Adapters make legacy code with modern classes.

Identification: Adapter is recognizable by a constructor which takes an instance of different abstract/interface type. When adapter receives a call to any of its methods, it translates parameters to appropriate format and then directs the call to one or several methods of the wrapped object.

Adapter in Other Languages

Design Patterns: Adapter in Java Design Patterns: Adapter in C# Design Patterns: Adapter in PHP Design Patterns: Adapter in Python Design Patterns: Adapter in Ruby Design Patterns: Adapter in TypeScript