A Swift library for parsing Garmin FIT (Flexible and Interoperable Data Transfer) files, specifically focused on dive computer data.
- Parse FIT files from Garmin dive computers
- Extract detailed dive information including:
- Session data (time, coordinates, temperature, depth)
- Dive summary (max depth, surface interval, bottom time)
- Dive settings (water type, gradient factors, PO2 limits)
- Tank data (pressure, volume)
- Dive profile points (depth, temperature, heart rate, tissue loading)
- Dive alerts and events
- Gas configurations
Add this package to your project using Swift Package Manager by adding it to your Package.swift
:
// swift-tools-version:5.5
import PackageDescription
let package = Package(
name: "YourProject",
platforms: [
.macOS(.v11),
.iOS(.v14)
],
products: [
.library(
name: "YourProject",
targets: ["YourProject"]),
],
dependencies: [
.package(url: "https://github.com/deepsealabs/fit-parser-swift.git", from: "1.2.0")
],
targets: [
.target(
name: "YourProject",
dependencies: ["FITParser"])
]
)
Or if you're using Xcode:
- Go to File > Add Packages...
- Enter package URL:
https://github.com/deepsealabs/fit-parser-swift.git
- Select version:
1.2.0
or higher
swift run FITParserCLI Sources/FITParser/TestDive4.fit
import FITParser
// Parse a FIT file
let result = FITParser.parse(fitFilePath: "Sources/FITParser/TestDive4.fit")
switch result {
case .success(let fitData):
// Access dive data
print("Max Depth:", fitData.summary.maxDepth ?? "N/A")
print("Dive Time:", FITParser.formatDuration(fitData.session.diveTime ?? 0))
// Access dive profile points
for point in fitData.divePoints {
print("Depth:", point.depth ?? "N/A")
print("Temperature:", point.temperature ?? "N/A")
}
case .failure(let error):
print("Error parsing FIT file:", error)
}
SessionData
: Overall dive session informationSummaryData
: Dive summary statisticsSettingsData
: Dive computer settingsDivePoint
: Individual data points throughout the diveDiveAlert
: Alerts and events during the diveDiveGas
: Gas mix configurations
// Access session data
let startTime = fitData.session.startTime
let maxDepth = fitData.session.maxDepth
let avgTemp = fitData.session.avgTemperature
// Access dive profile
for point in fitData.divePoints {
let depth = point.depth
let n2Load = point.n2Load
let cnsLoad = point.cnsLoad
}
// Access alerts
for alert in fitData.diveAlerts {
print("Alert:", alert.event ?? "Unknown")
print("Details:", alert.interpretedData ?? "No details")
}
- Swift 5.5+
- macOS 11.0+ / iOS 14.0+
Contributions are welcome! Please feel free to submit a Pull Request.