
Contents
Understanding team fixtures
Fixtures represent the scheduled matches for a team across a league, tournament, or season. They are essential for fans, clubs, broadcasters, and app developers, as they provide a roadmap of when and where a team plays.
What are team fixtures?
A team fixture refers to any match that a particular team is scheduled to play, whether it’s a league match, cup tie, or friendly. Fixtures usually contain:
– Match date and time: When the game is set to be played (including local and UTC time).
– Home and away teams: Identifies the venue and which team is hosting.
– Venue: Stadium information including name and location.
– League or tournament info: What competition the fixture belongs to (e.g. Premier League, Champions League).
– Match status: Whether the match is scheduled, ongoing, postponed, or completed.
Why fixtures matter in apps
Fixture data allows you to:
– Show upcoming and past matches for any team
– Send matchday notifications (e.g. “Your team plays tonight”)
– Prepare fantasy or prediction game logic (like locking selections before kickoff)
– Display form trends (e.g. won-last-3 or home-match streaks)
– Feed live scores and event updates as part of match-day views
What is Swift?
Swift is a modern, powerful, and easy-to-learn programming language developed by Apple. It’s designed to be fast, safe, and expressive, making it ideal for building iOS, macOS, watchOS, and tvOS applications.
Since its release in 2014, Swift has become the preferred language for Apple platform development, replacing Objective-C in most modern projects.
Key features of Swift
– Clean and readable syntax: Swift is concise and expressive, making it approachable for beginners and efficient for professionals.
– Type safety and inference: The language helps you avoid common bugs by checking types at compile time, while still allowing flexibility through inference.
– Performance-focused: Swift is built for speed. In many cases, it’s as fast as compiled C code and significantly faster than scripting languages.
– Safety-first design: With features like optionals and error handling, Swift encourages developers to write safe and predictable code.
– Modern development tooling: Swift works seamlessly with Xcode and has robust debugging, refactoring, and REPL support via Playgrounds and the Swift package manager.
Why use Swift for API integrations?
Swift is a great fit for integrating external APIs like Sportmonks’ football API because:
– Rich networking capabilities: Swift offers native support for HTTP via URLSession, and additional libraries like Alamofire make requests even easier.
– JSON decoding made simple: The built-in Codable protocol makes it straightforward to map JSON responses into usable Swift objects.
– Native mobile experience: Swift is the language of choice for building rich, interactive football apps on iPhones and iPads, from live scores to fixture schedules.
Where Swift is used
– Native iOS apps (e.g. iPhone and iPad)
– macOS desktop tools
– Watch apps (e.g. football match notifications)
– Backend APIs using frameworks like Vapor
Chapter 1. Setting up your environment
Before diving into code, it’s important to set up a Swift development environment that’s ready to handle HTTP requests, parse JSON, and connect to the Sportmonks football API. This chapter walks you through creating a basic Swift project, installing libraries, and managing your API token securely.
1. Install Xcode
Swift development is best done in Xcode, Apple’s official IDE. It includes everything you need:
– Code editor
– iOS simulator
– Project management tools
– Built-in support for version control and testing
Download Xcode:
– Open the Mac App Store
– Search for Xcode
– Install and launch it
2. Create a new Swift project
To build a football API-powered app or console tool:
- Open Xcode
- Select File > New > Project
- Choose App (or Command Line Tool if you’re building a simple script)
- Name it something like FootballAPIApp
- Choose Swift as the language
- Save the project to your workspace
3. Add networking capabilities
You can use native Swift libraries or third-party tools to make HTTP requests. For full control and simplicity, we’ll use Swift’s built-in URLSession.
If you prefer third-party tools (optional):
– Install Swift Package Manager (SPM) dependencies:
– Go to File > Add Packages
– Search for Alamofire (if you want simplified networking)
– Follow the prompts to add it to your target
4. Set up your Sportmonks API token
To access the football API:
- Go to my.sportmonks.com
- Log in or register
- Copy your API token
Use environment variables for security (recommended for command-line tools):
– Add the token to your terminal profile:
export SPORTMONKS_API_TOKEN=your_token_here
Access it in Swift:
let apiToken = ProcessInfo.processInfo.environment["SPORTMONKS_API_TOKEN"] ?? "fallback_token"
For Xcode apps (simpler alternative):
Add the token in a .plist file or store it in your app’s config manager (but avoid hardcoding it in production).
5. Create a simple test file
Test your setup with a minimal script. For example, let’s get the details for Manchester United:
import Foundation let apiToken = "your_token_here" let url = URL(string: "https://api.sportmonks.com/v3/football/schedules/teams/14?api_token=(apiToken)")! let task = URLSession.shared.dataTask(with: url) { data, _, error in if let data = data { print(String(data: data, encoding: .utf8) ?? "No data") } else { print("Error: (error?.localizedDescription ?? "Unknown error")") } } task.resume()
Run it in your main.swift file or inside a button action in your app to confirm everything is working.
Chapter 2: Retrieving fixture schedules using Swift
In this chapter, I’ll show you how to make a direct API call to Sportmonks’ football API and print the JSON response to the console.
Define the API request
Endpoint 1: Team schedule (current season)
Here’s a complete, minimal example using Swift’s built-in URLSession:
import Foundation func fetchTeamFixturesRaw(teamID: Int, apiToken: String) { let urlString = "https://api.sportmonks.com/v3/football/schedules/teams/(teamID)?api_token=(apiToken)" guard let url = URL(string: urlString) else { print("Invalid URL") return } let task = URLSession.shared.dataTask(with: url) { data, response, error in if let error = error { print("Request error: (error.localizedDescription)") return } guard let data = data else { print("No data returned") return } if let rawJSON = String(data: data, encoding: .utf8) { print("Raw API Response:n(rawJSON)") } else { print("Unable to convert data to string.") } } task.resume() }
How to use it
Call this function from viewDidLoad() (UIKit), onAppear() (SwiftUI), or a standalone script:
let teamID = 14 let apiToken = "YOUR_API_TOKEN" fetchTeamFixturesRaw(teamID: teamID, apiToken: apiToken)
Sample console output
Once the request completes, you’ll see something like this:
{ "id": 77476001, "sport_id": 1, "league_id": 3147, "season_id": 25277, "type_id": 223, "name": "Regular Season", "sort_order": 1, "finished": false, "is_current": false, "starting_at": "2025-07-26", "ending_at": "2025-08-03", "games_in_current_week": false, "tie_breaker_rule_id": null, "aggregates": [], "rounds": [ { "id": 369187, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "name": "2", "finished": false, "is_current": false, "starting_at": "2025-07-30", "ending_at": "2025-07-31", "games_in_current_week": false, "fixtures": [ { "id": 19399483, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "group_id": null, "aggregate_id": null, "round_id": 369187, "state_id": 1, "venue_id": 206, "name": "Manchester United vs AFC Bournemouth", "starting_at": "2025-07-31 01:30:00", "result_info": null, "leg": "1/1", "details": null, "length": 90, "placeholder": false, "has_odds": false, "has_premium_odds": false, "starting_at_timestamp": 1753925400, "participants": [ { "id": 14, "sport_id": 1, "country_id": 462, "venue_id": 206, "gender": "male", "name": "Manchester United", "short_code": "MUN", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/14.png", "founded": 1878, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-30 12:00:00", "meta": { "location": "home", "winner": null, "position": null } }, { "id": 52, "sport_id": 1, "country_id": 462, "venue_id": 146, "gender": "male", "name": "AFC Bournemouth", "short_code": "BOU", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/20/52.png", "founded": 1899, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-25 15:00:00", "meta": { "location": "away", "winner": null, "position": null } } ], "scores": [] } ] }, { "id": 369186, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "name": "1", "finished": false, "is_current": false, "starting_at": "2025-07-26", "ending_at": "2025-07-26", "games_in_current_week": false, "fixtures": [ { "id": 19399481, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "group_id": null, "aggregate_id": null, "round_id": 369186, "state_id": 1, "venue_id": 21826, "name": "Manchester United vs West Ham United", "starting_at": "2025-07-26 23:00:00", "result_info": null, "leg": "1/1", "details": null, "length": 90, "placeholder": false, "has_odds": false, "has_premium_odds": false, "starting_at_timestamp": 1753570800, "participants": [ { "id": 14, "sport_id": 1, "country_id": 462, "venue_id": 206, "gender": "male", "name": "Manchester United", "short_code": "MUN", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/14.png", "founded": 1878, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-30 12:00:00", "meta": { "location": "home", "winner": null, "position": null } }, { "id": 1, "sport_id": 1, "country_id": 462, "venue_id": 214, "gender": "male", "name": "West Ham United", "short_code": "WHU", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/1/1.png", "founded": 1895, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-25 15:00:00", "meta": { "location": "away", "winner": null, "position": null } } ], "scores": [] } ] }, { "id": 369188, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "name": "3", "finished": false, "is_current": false, "starting_at": "2025-08-03", "ending_at": "2025-08-03", "games_in_current_week": false, "fixtures": [ { "id": 19399485, "sport_id": 1, "league_id": 3147, "season_id": 25277, "stage_id": 77476001, "group_id": null, "aggregate_id": null, "round_id": 369188, "state_id": 1, "venue_id": 161191, "name": "Manchester United vs Everton", "starting_at": "2025-08-03 21:00:00", "result_info": null, "leg": "1/1", "details": null, "length": 90, "placeholder": false, "has_odds": false, "has_premium_odds": false, "starting_at_timestamp": 1754254800, "participants": [ { "id": 14, "sport_id": 1, "country_id": 462, "venue_id": 206, "gender": "male", "name": "Manchester United", "short_code": "MUN", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/14.png", "founded": 1878, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-30 12:00:00", "meta": { "location": "home", "winner": null, "position": null } }, { "id": 13, "sport_id": 1, "country_id": 462, "venue_id": 12, "gender": "male", "name": "Everton", "short_code": "EVE", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/13/13.png", "founded": 1878, "type": "domestic", "placeholder": false, "last_played_at": "2025-05-25 15:00:00", "meta": { "location": "away", "winner": null, "position": null } } ], "scores": [] } ] } ] },
Endpoint 2: Team schedule for a specific season
Use this when you want fixture data limited to a specific season, which is useful for filtering league-specific or historical match schedules
Swift example:
func fetchTeamFixturesBetween(startDate: String, endDate: String, teamID: Int, apiToken: String) { let urlString = "https://api.sportmonks.com/v3/football/fixtures/between/(startDate)/(endDate)/(teamID)?api_token=(apiToken)" fetchAndLogRawData(from: urlString) }
With this endpoint, we can build something like this;
Build smarter fixture features with Swift and Sportmonks
Bring real-time football schedules into your iOS app with ease. Using Sportmonks’ football API and Swift, you can fetch team fixtures, match dates, venues, and live updates, all optimised for a seamless mobile experience.
Whether you’re building a fan app, fantasy football platform, or match-day planner, integrating fixture data with Swift gives your users accurate and engaging content right on their device.
Start your free trial today and deliver dynamic football scheduling straight into your Swift applications.