A simple SwiftUI app that displays the current weather and a 3-day forecast for the user's current location. Users can also search for weather information in different cities.
- Display current weather and 3-day forecast for the user's current location.
- Search for weather information by city name.
- MVVM architecture for clean and maintainable code.
- Xcode 11 or later
- Swift 5.1 or later
- An API key from OpenWeatherMap
-
Clone the repository:
git clone https://github.com/yourusername/SwiftUIWeatherApp.git cd SwiftUIWeatherApp
-
Open the project in Xcode:
open SwiftUIWeatherApp.xcodeproj
-
Add your OpenWeatherMap API key:
- Open
WeatherService.swift
. - Replace
YOUR_API_KEY
with your actual OpenWeatherMap API key.
private let apiKey = "YOUR_API_KEY"
- Open
-
Update Info.plist:
- Add the following keys to request location permissions:
<key>NSLocationWhenInUseUsageDescription</key> <string>We need your location to provide weather updates.</string>
The app follows the MVVM (Model-View-ViewModel) architecture:
- Model: Defines the data structures (Weather, Forecast, etc.).
- ViewModel: Manages the data and business logic (WeatherViewModel).
- View: Displays the data (ContentView).
Models
: Contains data structures representing the weather data.ViewModels
: Contains the logic for fetching and managing weather data.Views
: Contains SwiftUI views that present the data.
- Run the app on your device or simulator.
- Allow location access when prompted to get the current weather for your location.
- Use the search bar to find the weather information for different cities.
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-06-11.at.16.52.13.mp4
This project is licensed under the MIT License - see the LICENSE file for details.