Skip to content

carlosmobile/OpenWeather

Repository files navigation

OpenWeather app example

Open weather view consists on a list of data hourly weather in your localization. The header of the view has a big view with the city name, the temperature, the current time, the icon and the description. Below the header, the view has an horizontal collection with weather next hours with the same info but in minor size.

  • This demo app support iPhone and iPad layouts and implements a open weather view.
  • This app is compatible with iOS 11 or higher.
  • The app uses swift package manager for dependency management.
  • All the user interface has been done using swift code. No Storyboards or xibs have been used.
  • The app has nit test and ui test with a coverage of 93%.

Open weather app meets the following requirements:

  • Supports Spanish and English languages. Gets the language that the user has selected in iOS.
  • Location support: Gets the coordinates and city name of the user's device.
  • Manage location permissions, following Apple's guidelines, using the own iOS libraries.
  • The app obtains the data from the Open Weather weather service. Getting the hourly forecast for today.
  • The app handle internet connection error control too.
  • Once the main screen is loaded, it allows you to reload the data by scrolling.


    WeatherViewController: Weather main view.
    WeatherViewModel: Weather viewModel.

Example gifs with iPhone 14 Xcode simulator:

openweather openweather

openweather openweather



Example image with iPad Pro (11 inch) Xcode simulator:

openweather



Architecture

I use MVVM, of course this is a flexible architecture and I can implement it in a basic or advanced way as needed. This project works with UIKit.

MVVM is a "reactive" architecture. Its a perfect fit to use Bindings. The view reacts to changes on the view model, and the view model updates its state based on data from the model.

MVVM involves three layers:

  • The model layer contains data access objects and validation logic. It knows how to read and write data, and it notifies the view model when data changes.

  • The view model layer contains the state of the view and has methods to handle user interaction. It calls methods on the model layer to read and write data, and it notifies the view when the model’s data changes.

  • The view layer styles and displays on-screen elements. It doesn’t contain business or validation logic. Instead, it binds its visual elements to properties on the view model. It also receives user inputs and interaction, and it calls methods on the view model in response.

    As a result, the view layer and model layer are completely decoupled. The view layer and model layer only communicate with the view model layer but we can binding model to view with Combine if we need to use reactive programming way.

This architecture has been used because it's considered an advance architecture that modulates the code and respect the clean code, SOLID principles and the best practices.



Tools

  • Bindable: Helper to use reactive programming without external library.
  • LocationManager: To manage user location.
  • OWReachability: To handle internet error.
  • SpinnerController: To show a way to know if views are loading weather data.
  • Utils: Some global functions to get weather url icon or to get hourly time with format


Common

Extension class

Model

Structs:

Networking



Tests

This app test ViewModels, Models, Helpers, Common components, mock data, etc.. with

XCTests/UITests


Test Coverage 93%



Swift Guide Style

The app code follows the Ray Wenderlich Swift Style Guide.

Centralized data

The app uses in "support" logical folder a ThemeManager.swift class to support centralized colors. It also uses multilanguage with Localizable.strings to centralized all the text in the app.

Swift Package Manager

  • Kingfisher: Used to implement an easy way to download images from server with animation spinner and fade.


GitFlow

This app is developed using GifFlow, using only git commands and tool sourcetree.

Design

The app try to implement nice design and UI/UX, respecting the iOS native elements as Apple guidelines and have a correct layout and implement the safe areas to correct view in last iPhone models.



Getting Started

Running in Xcode 14.3 and iOS 16.4 Written in Swift 5

Next..

Add animated background, show more weather info, improve error control, etc..

Releases

No releases published

Packages

No packages published

Languages