Repository Design Pattern in Swift

A clean way to query your models

What problem does it solve?

Sketching the scene.

  1. A GET request to the server
  2. Maps the returned JSON to an array of Article objects
  3. The closure gets called when all the work is done.

Why do we need a repository?

Hello repository.

Handle all article interactions

Power-up: protocols

Power-up: Unit Testing

An example

Hello, dependency injection.

Super power-up: generics

  1. get all the things
  2. get some of the things
  3. insert some things
  4. delete thing
  5. update a thing

1. Article repository

2. User Repository

That’s it.

--

--

Freelance iOS consultant. Currently helping out at Dutch Railways.

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
Frederik Jacques

Freelance iOS consultant. Currently helping out at Dutch Railways.