Weather App Tutorial
⏱️ 45 minutes Build a weather app that shows current conditions and forecasts. You’ll learn about API integration, location services, and displaying real-time data.What You’ll Build
A weather app that:- Shows current weather for your location
- Displays temperature, conditions, and other details
- Shows a multi-day forecast
- Lets you search for other cities
Before You Start
This tutorial uses a weather API to get real data. You have two options:Option A: Use WeatherKit (Recommended)
Apple’s built-in weather service. No API key needed, but requires iOS 16+ and works automatically.Option B: Use OpenWeather API
Free tier available at openweathermap.org. Requires creating an account and getting an API key. For this tutorial, we’ll use WeatherKit since it’s simpler.Part 1: Create the App
On the Nativeline home page, enter:Complete the Wizard
- Who is this for? — Just me
- Feel — Modern & polished
- Priority — Core functionality first
- Colors — Ocean Blues (or your choice)
- Name — Weather
Part 2: Set Up Location Permission
Your app needs permission to access location. Nativeline should have set this up, but let’s verify:- You’ll see a permission popup for location
- Tap “Allow While Using App”
- The app should fetch weather for the Simulator’s default location
Part 3: Improve the Current Weather Display
Let’s make the current weather look better:Part 4: Add Weather Details
Add more weather information:Part 5: Improve the Forecast
Let’s enhance the 5-day forecast:Part 6: Add City Search
Let users check weather for other cities:Part 7: Add Pull to Refresh
Let users manually refresh the weather:Part 8: Add Background Based on Weather
Make it visually dynamic:Part 9: Add Hourly Forecast (Optional)
Show hour-by-hour weather:Part 10: Add Weather Alerts (Optional)
Display severe weather warnings:Final Result
You now have a complete weather app with:- ✅ Current location weather
- ✅ Temperature and conditions
- ✅ 5-day forecast
- ✅ Weather details (humidity, wind, etc.)
- ✅ City search
- ✅ Pull to refresh
- ✅ Dynamic backgrounds
- ✅ (Optional) Hourly forecast
- ✅ (Optional) Weather alerts
What You Learned
| Concept | How It Was Used |
|---|---|
| APIs | Fetching weather data from WeatherKit |
| Location | Getting device coordinates |
| Permissions | Requesting location access |
| Async data | Loading states and refreshing |
| Search | City lookup and selection |
| Dynamic UI | Backgrounds based on conditions |
Using OpenWeather API Instead
If you prefer OpenWeather (or WeatherKit isn’t working):- Sign up at openweathermap.org
- Get your free API key
- Tell Nativeline:
Troubleshooting
Weather data not loading
Weather data not loading
- Make sure location permission is granted
- Check that you’re connected to the internet
- Try the Simulator’s Features → Location menu
- Try asking: “Show a mock weather display with sample data to test the UI”
Location permission not appearing
Location permission not appearing
The permission popup only shows once. To reset:
- Simulator → Device → Erase All Content and Settings
- Or ask: “Make sure we request location permission with a usage description”
Search not finding cities
Search not finding cities
“Use Apple’s MapKit geocoding to search for cities by name”
WeatherKit not working
WeatherKit not working
WeatherKit requires iOS 16+. Make sure your Simulator is running iOS 16 or later, or switch to OpenWeather API.
Challenge: Extend Your App
Try these on your own:- Widgets — Create a home screen widget (advanced)
- Favorites — Save favorite cities
- Notifications — Alert when rain is expected
- Units toggle — Switch between °F and °C
- Radar map — Show weather radar for your area