How do I add exercise data to a SwiftUI app?
Fill a SwiftUI list and detail screen with one exerciseapi.dev request. Set up your key in Xcode and keep one null field from breaking the whole list.
One request fills both screens
One request gives you the names for a SwiftUI List and the steps for each detail screen. Put the List inside a NavigationStack so a tap can open the detail screen. Fetch the list with URLSession, save it on the phone, then pass the selected exercise through a NavigationLink. A tap takes no extra call.
Our library covers 2,200 exercises across 12 disciplines. Say you want 20 strength exercises for your first screen. Each result is a full exercise record, even on the free plan.
Where the key goes
Put EXERCISEAPI_KEY = your_key in an .xcconfig file that git ignores. In the project’s Info tab, under Configurations, select that file for both Debug and Release. A new Xcode project may have no Info.plist file. Create one if needed. In that file, add EXERCISEAPI_KEY with the value $(EXERCISEAPI_KEY). Point the app target’s Info.plist File build setting to that file. Read it with Bundle.main.object(forInfoDictionaryKey: "EXERCISEAPI_KEY") as? String and send it in the X-API-Key header. If the plist entry is missing, the app sends no key and gets a 401.
You can ship the key in a published iOS app. Keeping it out of git protects the source, but anyone with the built app can read it. We found our made-up key as plain text in the Release build’s Info.plist. For a web version, keep the key on your own server and have the web app call that server.
Which fields need a Swift optional?
The list response has a data array of exercise records and a total. The /v1/exercises/:id response returns data as one record, so you need two wrapper types. Declare total as Int? because it can be null when you search with q. In each record, declare equipment, force and mechanic as String?. All other fields have values, though a list can be empty.
We tried a plain String for mechanic. Of the first 20 yoga results, 13 had a null there. JSONDecoder threw valueNotFound on the first null, so the whole list failed to decode. We then decoded the same 20 results with the full model described here.
What to show when someone taps
Open the steps and form tips from the saved row. The same record includes common mistakes, safety notes and variations. If a saved workout or link gives you only an id, fetch /v1/exercises/:id. Use the id from an API response. Building it from the name can give you the wrong id.
333 of our 2,200 exercises have a demo. The videos field is an array of objects, each with a url. If you declare it as [String], decoding fails on the first clip. If videos.isEmpty is true, show the steps and tips without a player. Add hasVideo=true to the query when every result needs a demo.
How long to keep a list
Store the response data and a fetchedAt date in one Codable struct. Write it as JSON in Application Support. Have FileManager create the folder if it’s missing. Each request URL needs its own file. Use CryptoKit’s SHA-256 hash of the URL as the filename so its slashes don’t become part of the path. On every launch, remove all saved files more than 30 days old. That keeps a search nobody repeats from staying on the phone.
Under 24 hours, show the copy without a call. Once the copy is 24 hours old, show it right away and fetch a fresh copy in the background. Offline, you may show a copy up to 30 days old. Remove older copies, even offline. Fetch a fresh copy before showing the data again. Use the same rule for /v1/categories, /v1/muscles and /v1/equipment. Those lists change even less often.
URLSession keeps its own cache of responses. In our test on a Mac, URLSession answered a repeat request from its own cache. Make one URLSession for the API with a URLSessionConfiguration whose urlCache is nil. Then your JSON files are the only copy. With that setting, our simulator app left no URLSession cache database. Before saving the response, check that the HTTPURLResponse status code is 200. URLSession’s data(for:) doesn’t throw for 401 or 429. Decode the response before it replaces the saved file.
What we checked
On December 2, 2026, we tested a SwiftUI app against the live API with Xcode 26.0.1 and an iPhone simulator running iOS 26. The first open took one call for 20 exercises. We tapped the first row and its steps opened without another call. Reopening the list took zero calls.
We changed the saved time in code. At 25 hours, all 20 rows were on screen while the refresh call was still running. That one call refreshed the list. We then switched calls off in code to test the 30-day limit. The 25-hour and 29-day copies opened. The app removed the 31-day file from storage, and the list stayed empty until we switched calls back on. At launch, the app also removed a 31-day-old search we never reopened.
The id lookup and all three reference lists worked. The run took seven calls. We checked decoding and URLSession’s default cache with Swift programs that ran on a Mac and called the live API. To check the key, we opened a Release build for iOS on the Mac. We didn’t test a real iPhone.
Get your first 20 exercises
Your free account gets 100 requests a day. Every phone with your app installed shares that limit. Exercise searches return up to 20 results per page, and you can page through the first 500 results of each query. Get a free key from exerciseapi.dev without a card, then send this request with your key in the X-API-Key header.
GET https://api.exerciseapi.dev/v1/exercises?category=strength&limit=20&offset=0