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:
Example image with iPad Pro (11 inch) Xcode simulator:
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.
- 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
- WeatherHeaderCell: To show big header current weather.
- WeatherHourlyCollection: To load a collection with hourly weather.
- WeatherHourlyCell: Cell with data of each collection hourly weather.
- FooterSheetView: To show location alert and internet error alert
- String+Extension: Useful string extension to manage multilanguage or capitalized first letter of string.
- UIView+GradientColor: To generate an amazing gradient color to main background.
- UIImageView+DownloadImage: To manage third party library to download images.
- Locale+LanguageCode: To get current local language code.
Structs:
- WeatherModel: To model Weather data.
- APIConfiguration: Struct and enum to centralized network url and others.
- APIRequest: Class to implement request configuration.
- APIResponse: Extension to decode API response.
- APIError: Enum to handle error type.
- APIClient: Class to implement URLSession.
- SessionProtocol: URLSession dataTask.
This app test ViewModels, Models, Helpers, Common components, mock data, etc.. with
XCTests/UITests
- TestAPIClient: Test Network layer.
- TestHelpers: Test Tools and extensions .
- TestModel: Test WeatherModel.
- TestViewModels: Test WeatherViewModel.
- OpenWeatherUITests
Test Coverage 93%
The app code follows the Ray Wenderlich Swift Style Guide.
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.
- Kingfisher: Used to implement an easy way to download images from server with animation spinner and fade.
This app is developed using GifFlow, using only git commands and tool sourcetree.
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.
Running in Xcode 14.3 and iOS 16.4 Written in Swift 5
Add animated background, show more weather info, improve error control, etc..