Code Monkey home page Code Monkey logo

stackoverflowtopusers's Introduction

A sample project with zero dependencies showing how to retrieve and show the top list of users from the StackOverflow API.

Testing

I've included a sample response in the testing bundle so we can validate tests against a known response and not hit the network. Before writing any code, I tend to inspect an API using Paw. In the past i've set up team instances of this so we can share API structures, add upcoming API requests etc.

Model

Models are decoded off the network using Swift's Decodable mechanism.

Network client

A thin wrapper around URLSession for testability. Requests made to the network conform to Request, and responses are decoded using Parsable - both Codable objects and custom responses (such as from an image request).

TopUsersRequest

TopUsersRequest conforms to the Request protocol, which describes a call that can be made to the network.

TopUsersContext

Contexts wrap data fetching functionality for a View Model, creating a separation between making a network request and receiving data. These can be stubbed out in tests to just return the data.

Home launch sequence

When launching, the HomeViewModel receives a request from the HomeViewController to fetch users. These are then passed to the HomeDataSource, which understands how to enrich them with local state that the UserCell can handle (expanded state, blocked, followed, etc).

I'll often use something like Bond to make this binding easier - negating the need for the datasource.

Profile images are requested as the cells dequeue using a ProfileImageContext, which uses Session underneath.

stackoverflowtopusers's People

Contributors

sebskuse avatar

Watchers

 avatar  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.