Giter VIP home page Giter VIP logo

thepromisedland's Introduction

The promised land

Demo project demonstrating how to build a service layer with promises, request behaviours and child view controllers.

Motivation

Writing asynchronous code in Swift can be a cumbersome process when chaining requests, adding proper error handling and indicating status of network operation.

When chaining two or more request or functions invoked asynchronosuly, what we do frequently is nesting completion handlers and adding invocation of same error handler in several places, same with handling network activity indicator:

    func trigger() {
    	showActivityIndicator()
        send(completion: { [weak self] (model) in
            self?.ack(model: model, completion: {
                self?.hideActivityIndicator()
            }, error: { (error) in
                self?.hideActivityIndicator()
                self?.handle(error: error)
            })
        }) { (error) in
            self?.hideActivityIndicator()
            self?.handle(error: error)
        }
    }

What if this code, could be simply transformed to:

   func trigger() {
        send().then { [weak self] (model) in
            return self?.ack(model: model)
        }.then { (_) in
           ...
        }
    }

How to compile?

carthage update --platform iOS

and then compile with Xcode 10+

Presentation

This project was created for the purpose of "The promised land" presentation, which content can be found here.

References

This Demo project demonstrates a design pattern based on Promises, Request Behaviours and Child View Controllers.

Inspired and based on great work from Soroush Khanlou

thepromisedland's People

Contributors

tgebarowski avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.