Skip to content

MercuryAtom31/WeatherApp-Final-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WeatherApp

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.


Table of Contents

  1. Features
  2. Technologies Used
  3. Folder Structure
  4. Setup Instructions
  5. Code Quality and Practices

Features

🌀 Current Weather Conditions

  • 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).

πŸ“… Daily and Hourly Forecasts

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

πŸ“Š Historical Weather Data

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

πŸ“° Weather News

  • Displays weather-related news articles with titles, descriptions, and "Read More" links.
  • Links to trusted weather news sources (e.g., WeatherBug).

πŸ—Ί Interactive Weather Map

  • Allows users to view map pins with random weather conditions for selected coordinates.
  • Smooth map interactions via MapKit integration.

Technologies Used

  • 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

Folder Structure

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/

Setup Instructions

Prerequisites

  1. Xcode 15+: Ensure Xcode is installed on your system.
  2. iOS Simulator or Device: Run the app on a simulator (iOS 18) or a physical iPhone device.

Steps to Run

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

  1. Clone this repository to your local system:
    git clone https://github.com/yourusername/WeatherApp.git](https://github.com/MercuryAtom31/WeatherApp-Final-Project.git
  2. Open the project in Xcode:
    cd WeatherApp
    open WeatherApp.xcodeproj
  3. Ensure the required JSON files are present in the Resources folder.
  4. Run the project:
    • Select a simulator or device.
    • Press Cmd + R or click the Run button in Xcode.

Code Quality and Practices

  • 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).

APIs Used in WeatherApp

1. OpenWeather API

  • 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
      

2. Open-Meteo API

  • 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
      

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.


Acknowledgments


Screenshots

Current Weather

Screenshot 2024-12-15 at 22 42 43

Historical Weather

Screenshot 2024-12-15 at 22 42 16

Historical Weather Sorting by keyword

Screenshot 2024-12-15 at 22 42 16

Weather News

Screenshot 2024-12-15 at 22 43 01

When you click on one of the weather news article

Screenshot 2024-12-15 at 22 43 10

When you pin a specific city to get its current weather conditions

Screenshot 2024-12-15 at 22 43 29

Screenshot 2024-12-15 at 21 05 25

Screenshot 2024-12-15 at 21 05 34


Enjoy exploring the WeatherApp! 🌦✨

About

WeatherApp is an iOS app built with Swift and SwiftUI to deliver real-time weather updates, seven-day forecasts, historical data, and weather news. It integrates the OpenWeather API, Open-Meteo API, and local JSON data for accurate and dynamic weather information. Key Features: 🌀 Current Weather: Temperature, humidity, wind speed πŸ“… Forecasts: D

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages