Better Programming

Advice for programmers.

Follow publication

WWDC22: Get Started With WeatherKit

Apple’s new free API lets you make 500,000 API calls per month for free

Millie Dev
Better Programming
Published in
3 min readJun 7, 2022
Image by Pexels from Pixabay

A lot of the complexity of getting WeatherKit up and running is getting the right capability in place. Go to create an App ID on Apple’s Developer website.

You will need to enable WeatherKit on BOTH of the tabs called Capabilities and App Services. Your bundle identifier will need to be explicit, and you will need to wait at least 30 minutes after creating your App ID before trying to use WeatherKit.

Screenshots by the author

Now create a new app project in Xcode 14 beta, making sure to add the WeatherKit capability on the Signing and Capabilities tab of your project file, as seen below.

Screenshot by the author

So hopefully you’ve created your App ID with the right capabilities and app services and waited half an hour, then you’ve created an app project with the same bundle ID as your App ID, and finally you’ve added that capability to your project file.

Now we can actually get to the fun part, which is making a SwiftUI interface that displays weather data.

To keep this simple I’m making an app that only displays the temperature in Cupertino at the current time:

The latitude and longitude of Cuptertino were calculated using latlong.net and saved as a static CLLocation object. In order to make the temperature big on the screen, a huge font size was selected with a minimum scale factor. This is how we access the ‘auto-shrink’ feature as it was known in UIKit. The line limit is used so that the units are not put onto a second line, which will happen if the string gets too long.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Millie Dev
Millie Dev

Written by Millie Dev

An iOS developer who writes about gadgets, startups and blockchains. Swift programming tutorials are at typesafely.co.Uk

Responses (3)

Write a response