Kodeco Forums

How to make a RESTful app with Siesta

Learn how you can use the Siesta framework to improve your API interactions, networking, model transformations, caching, loading indications and more.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429-how-to-make-a-restful-app-with-siesta

What a wonderful tutorial, but there is a tiny mistake.
Above the sentence, “extension RestaurantListViewController: UITableViewDelegate” ,RestaurantDetailsViewController.swift should be RestaurantListViewController.swift

@sanketfirodiya Can you please fix this when you get a chance? Thank you - much appreciated! :]

@ys_xs thanks for catching that, should be fixed now :]

I like this tutorial, but im Mexican, and we not sleep many!! , I don’t like this image… :smile:

Nice tutorial! Just one thing is bothering me:

TL;DR: You should instantiate the decoder inside configuration closure instead of capturing an instance. Otherwise you’re calling for trouble.

Long version: Siesta’s transformer pipeline is dispatched asynchronously on background queue, and there are no guarantees of serial execution for transformers (unlike request hooks for example, which always run on the main queue). If you use a captured instance, you’re effectively sharing it between all invocations of response transformer for this partucular url, which can occur simultaneously. JSONDecoder is declared as class, meaning that it has a state which can be mutated during the decoding. Therefore we cannot blindly assume that it has some thread safety built in (even if it actually does), unless the class reference explicitly states this (it does not).

P.S. Strictly speaking, business-logic of the tutorial app does not allow two requests to happen simultaneously. But often it can be not that trivial or even not desirable to implement and maintain such guarantees in real-world app. It’s much simpler and safer to just instantiate the decoder at call site, and it’s cheap.

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!