FITParser

1.3.0

FIT File Parser for Swift Applications
deepsealabs/fit-parser-swift

What's New

2025-04-23T12:13:46Z

Release v1.3.0

Features

  • Suunto Ocean Support: Added parsing capabilities and handling for FIT files generated by Suunto Ocean devices, including generating lap data when missing.
  • Tolerates missing Summary and Settings messages for broader file compatibility.
  • Includes File ID information in the parsed output.

Fixes

  • Resolved build issues related to manufacturer code constants.
  • Correctly extracts lap start/end coordinates from record messages when not present in the session message.

FIT Parser Swift

GitHub forks GitHub stars License

A Swift library for parsing Garmin FIT (Flexible and Interoperable Data Transfer) files, specifically focused on dive computer data.

Features

  • 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

Installation

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:

  1. Go to File > Add Packages...
  2. Enter package URL: https://github.com/deepsealabs/fit-parser-swift.git
  3. Select version: 1.2.0 or higher

Usage

Command Line Interface

swift run FITParserCLI Sources/FITParser/TestDive4.fit

Library Usage

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)
}

Data Structures

Main Components

  • SessionData: Overall dive session information
  • SummaryData: Dive summary statistics
  • SettingsData: Dive computer settings
  • DivePoint: Individual data points throughout the dive
  • DiveAlert: Alerts and events during the dive
  • DiveGas: Gas mix configurations

Example Data Access

// 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")
}

Requirements

  • Swift 5.5+
  • macOS 11.0+ / iOS 14.0+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Tue May 13 2025 05:43:39 GMT-0900 (Hawaii-Aleutian Daylight Time)