This app is using web-socket for realtime updation of aqi for dedicated inidan cities.

Overview

CityWiseAQI

This app is using web-socket for realtime updation of aqi for dedicated inidan cities.

Screenshots

We're following MVVM architecture in this app. This app has two modules:-

  1. Listing of All Cities
  2. AQI Chart for selcted City

1. Listing of All Cities

ViewModel:-

  1. Here App is establishing connection with WebSocket server. For that, app is using one library(Starscream).
  2. Once App is connected to the server, App start getting realtime data and keep parsing the data into a desired model called AirQualityInfo.
  3. I have created two more models called City & AQI.
  4. I have created array of unique Cities(if any city already exists then keep updating the past history of aqi),
  5. While updating the past history of aqi in a city, we add first two values of aqi directly and then we only add aqi values after 30 seconds(because in chart we're showing aqi on 30 seconds interval).
  6. City updation task we're doing on an internalQueue with .barrier flag, to get better ui performance.
  7. ViewModel builds tableview models. Once done ViewModel updates to ViewController to update the UI.
  8. We also check if ViewModel has any selected city delegate, if yes then ViewModel also pass the updated aqi to the ViewModel of CityAqiDetails.
  9. If WebSocket occurs any error then ViewModel also updates to the ViewController for retry connection.

ViewController:-

  1. ViewController is listening events from ViewModel and updating the ui.
  2. For better outcome, app is disconnecting from web-socket when enters on background and reconnecting to the web-socket when enters on foreground.
  3. If WebSocket occurs any error then showing a alert to user for retry connection.

Model:-

  1. AirQualityInfo:- it represents data coming from web-socket server.
  2. City:- This is for tableview cell, it has all required info for table cell, to make table cell light weight.
  3. AQI:- This is for chart, on the basis of last record time of AQI model, we're checking the differnece, if it is equal to or greater than 30 seconds then only we update the chart with next AQI.

2. AQI Chart for selcted City

ViewModel:-

  1. This ViewModel is confirming to the delegate of city-listing-ViewModel to get the real time udpated aqi.
  2. We're adding first two aqi objects into records to shat chart doesn't look odd, after that we're checking the differnece of updated aqi & last recorded aqi, if it is equal to or greater than 30 seconds then only we recoed the updated one and update the chart.
  3. We're maintaining records of 25 aqi, if aqi records reaches to 25, we're removing the first added aqi from records.
  4. On the basis of aqiRecords, we're making LineChartDataSet for Charts. Once done we pass to the ViewController to update the chart.

ViewController:-

  1. For chart, We're using one library called Charts.
  2. We're using line chart here.
  3. once ViewController recives the updated LineChartDataSet, chart has been udpated.

We also have one enum called AQILevel, which has all the required methods like:-

  1. getAqiLevel():- to get to know the level of AQI.
  2. getDesc():- for displaying the AQILevel.
  3. getColor():- to get the dedicated color of an AQILevel.
  4. getFace():- in our UI we're shpwing few emoji, to explain the AQILevel in a better way, so this function is for this purpose.

Time Invested:-

  1. Socket: 4 hours
  2. Cities listing: 2 hours
  3. Charts:- 3 hours
  4. Project setup & Handling of use cases:- 1 hour

Overall around 10 hours have been invested on it.

You might also like...
💧 A server-side Swift web framework.
💧 A server-side Swift web framework.

Vapor is a web framework for Swift. It provides a beautifully expressive and easy to use foundation for your next website, API, or cloud project. Take

A Swift web framework and HTTP server.
A Swift web framework and HTTP server.

A Swift Web Framework and HTTP Server Summary Kitura is a web framework and web server that is created for web services written in Swift. For more inf

A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X

IMPORTANT! We don't see any way how to make web development as great as Ruby on Rails or Django with a very static nature of current Swift. We hope th

Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

WKZombie is an iOS/OSX web-browser without a graphical user interface.
WKZombie is an iOS/OSX web-browser without a graphical user interface.

WKZombie is a Swift framework for iOS/OSX to navigate within websites and collect data without the need of User Interface or API, also known as Headless browser. It can be used to run automated tests / snapshots and manipulate websites using Javascript.

A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

A minimal, fast and unopinionated web framework for Swift

![Fire Image] (http://i.imgur.com/1qR6Nl4.png) Blackfire An extremely fast Swift web framework 🔥 Getting Started If you're familiar with express.js t

Swift Express is a simple, yet unopinionated web application server written in Swift
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation h5 align="right"a href="http://demo.swiftexpress.io/"Live 🐧 server running Demo img src="https://cdn0.iconfinder.com/data/icons/

Frank is a DSL for quickly writing web applications in Swift

Frank Frank is a DSL for quickly writing web applications in Swift with type-safe path routing. Sources/main.swift import Frank // Handle GET request

Owner
Vipul Kumar
I make apps in { Swift , Objective-C } for iOS {iPhone+iPad}.
Vipul Kumar
Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM

AQI Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM This app follows MVVM This app uses combine framework The

Amey Vikkram Tiwari 2 Nov 6, 2022
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-5.1

Kitura 1.3k Dec 26, 2022
🔌 Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

Vapor Community 574 Dec 7, 2022
Socket.io iOS and OSX Client compatible with v1.0 and later

SocketIO-Kit ⚠️ This project is no longer maintained. Please use the official framework Socket.IO-Client-Swift. SocketIO-Kit is a Socket.io iOS client

Ricardo Pereira 140 Mar 9, 2022
DispatchSource based socket framework written in pure Swift

SwiftDSSocket Overview SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty m

Yi Huang 65 Nov 15, 2022
Asynchronous socket networking library for Mac and iOS

CocoaAsyncSocket CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for macOS, iOS, and tvOS. The classes are described

Robbie Hanson 12.3k Jan 8, 2023
Swift async/await based socket

Socket Swift async/await based socket library Introduction This library exposes an idiomatic Swift API for interacting with POSIX sockets via an async

null 89 Dec 29, 2022
This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app.

This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and Apple TV app. With this Framework you can create iPh

Prioregroup.com 479 Nov 22, 2022
A web API client in Swift built using Async/Await

Get A modern web API client in Swift built using Async/Await and Actors. let cli

Alexander Grebenyuk 745 Jan 3, 2023
Robust Swift networking for web APIs

Conduit Conduit is a session-based Swift HTTP networking and auth library. Within each session, requests are sent through a serial pipeline before bei

Mindbody 52 Oct 26, 2022