WeatherApp is a modern iOS application that provides current weather data, seven-day forecasts, historical weather information, and weather-related news. Built with Swift and SwiftUI, the app integrates local static JSON data and live weather APIs to deliver a seamless user experience with clean, functional design.
- Displays the current weather, including temperature, humidity, wind speed, and a weather icon.
- Integrates with the Open-Meteo API to fetch real-time data.
- Dynamic backgrounds change based on weather conditions (e.g., clear sky, snow, rain).
- Provides a 7-day weather forecast with minimum and maximum temperatures.
- Shows an hourly breakdown of the weather conditions.
- Scrollable views for easy navigation of forecasts.
- Fetches and displays weather information from a static local JSON file.
- Sorting capabilities based on date, temperature (high/low), wind speed, and humidity.
- Filter functionality to search by weather condition.
- Displays weather-related news articles with titles, descriptions, and "Read More" links.
- Links to trusted weather news sources (e.g., WeatherBug).
- Allows users to view map pins with random weather conditions for selected coordinates.
- Smooth map interactions via MapKit integration.
- Language: Swift, SwiftUI
- API Integration: OpenWeather API and Open-Meteo API
- Frameworks: MapKit, SwiftUI
- Storage: Local JSON Files (
local_weather.json,news_articles.json) - Tools: Xcode 15, iOS Simulator
WeatherApp/
βββ Features/
β βββ Model/
β β βββ DailyWeather.swift
β β βββ Forecast.swift
β β βββ ForecastResponse.swift
β β βββ HistoricalWeather.swift
β β βββ HourlyWeather.swift
β β βββ Location.swift
β β βββ MapPinData.swift
β β βββ OpenMeteoModels.swift
β β βββ Weather.swift
β β βββ WeatherNews.swift
β β
β βββ ViewModel/
β β βββ DailyForecastViewModel.swift
β β βββ HistoricalWeatherViewModel.swift
β β βββ HourlyForecastViewModel.swift
β β βββ WeatherNewsViewModel.swift
β β βββ WeatherViewModel.swift
β β βββ WeeklyForecastViewModel.swift
β β
β βββ View/
β βββ CurrentWeatherView.swift
β βββ DailyForecastView.swift
β βββ HistoricalWeatherView.swift
β βββ HourlyForecastView.swift
β βββ MainWeatherView.swift
β βββ MapViewRepresentable.swift
β βββ WeatherBackground.swift
β βββ WeatherDetailsView.swift
β βββ WeatherMapView.swift
β βββ WeatherNewsView.swift
β βββ WeeklyForecastView.swift
β
βββ Resources/
β βββ local_weather.json
β βββ news_articles.json
β βββ Assets.xcassets
β
βββ Services/
β βββ LocationManager.swift
β βββ OpenMeteoService.swift
β βββ WeatherService.swift
β
βββ App/
β βββ WeatherAppApp.swift
β βββ ContentView.swift
β βββ StringExtensions.swift
β
βββ Tests/
β βββ WeatherAppTests/
β βββ WeatherAppUITests/
β
βββ Preview Content/
βββ Preview Assets/
- Xcode 15+: Ensure Xcode is installed on your system.
- iOS Simulator or Device: Run the app on a simulator (iOS 18) or a physical iPhone device.
IMPORTANT
Inside the services folder, the WeatherService class is responsible for fetching weather data from the OpenWeather API.
You must replace the placeholder value below with your actual API key.
You can obtain an API key by signing up at the OpenWeather API website.
Example:
private let apiKey = "get_your_api_key_from_OpenWeather_API"IMPORTANT
- Clone this repository to your local system:
git clone https://github.com/yourusername/WeatherApp.git](https://github.com/MercuryAtom31/WeatherApp-Final-Project.git
- Open the project in Xcode:
cd WeatherApp open WeatherApp.xcodeproj - Ensure the required JSON files are present in the
Resourcesfolder. - Run the project:
- Select a simulator or device.
- Press
Cmd + Ror click the Run button in Xcode.
- Clean Code:
- Code adheres to Swift naming conventions and clean coding practices.
- Classes and files are logically organized (MVVM architecture).
- Comments:
- Each class, method, and critical section of the code has descriptive comments.
- Example:
/// Fetches the current weather for a given city name. func fetchWeatherData(for city: String) { ... }
- Error Handling:
- Safe decoding of JSON files with appropriate error handling.
- Random placeholder data is generated for weather map pins when needed.
- Scalability:
- Easy to add new features (e.g., additional weather conditions, API endpoints).
- Base URL:
https://api.openweathermap.org/data/2.5/ - Endpoints:
- Current Weather: Fetches real-time weather data for a city.
Example:https://api.openweathermap.org/data/2.5/weather?q=Montreal&appid=YOUR_API_KEY&units=metric - Hourly Forecast: Retrieves hourly weather data.
Example:https://api.openweathermap.org/data/2.5/forecast?q=Montreal&appid=YOUR_API_KEY&units=metric - Daily Forecast: (Optional) Provides 7-day forecasts.
Example:https://api.openweathermap.org/data/2.5/forecast/daily?q=Montreal&cnt=7&appid=YOUR_API_KEY&units=metric
- Current Weather: Fetches real-time weather data for a city.
- Base URL:
https://api.open-meteo.com/v1/forecast - Endpoint:
- Daily Weather Data: Fetches daily high/low temperatures and weather codes.
Example:https://api.open-meteo.com/v1/forecast?latitude=45.5088&longitude=-73.5878&daily=temperature_2m_max,temperature_2m_min,weathercode&timezone=America%2FToronto
- Daily Weather Data: Fetches daily high/low temperatures and weather codes.
These APIs power the app's real-time weather updates, hourly forecasts, and daily forecasts, enabling a rich user experience.
Make sure to replace YOUR_API_KEY with a valid API key for OpenWeather API.
- Open-Meteo API
- OpenWeather API
- WeatherBug News
- Built with β€οΈ using SwiftUI and MapKit.
Enjoy exploring the WeatherApp! π¦β¨







