### Swift Package Installation and Module Imports Source: https://context7.com/garmin/fit-objective-c-sdk/llms.txt Instructions on how to install the FIT SDK using Swift Package Manager and import the necessary modules for both Swift and Objective-C projects. ```APIDOC ## Swift package installation and module imports The SDK is distributed as a Swift Package. After installation, import the appropriate modules based on which API layer you need. The `SwiftFIT` module is required only for `FITListener` and `FITMessages`; pure Objective-C projects use `@import ObjcFIT` alone. ```swift // Swift — basic decode/encode (no FITListener) import ObjcFIT // Swift — high-level FITListener + FITMessages API import ObjcFIT import SwiftFIT ``` ```objc // Objective-C @import ObjcFIT; ``` ```swift // Package.swift dependency (when used in another package) dependencies: [ .package(url: "https://github.com/garmin/fit-objective-c-sdk", from: "21.202.0") ], targets: [ .target(name: "MyTarget", dependencies: [ .product(name: "FIT", package: "fit-objective-c-sdk") ]) ] ``` ``` -------------------------------- ### FITSessionMesg, FITLapMesg, and FITLengthMesg Usage Source: https://context7.com/garmin/fit-objective-c-sdk/llms.txt Examples demonstrating how to create and populate FITSessionMesg, FITLapMesg, and FITLengthMesg objects for tracking exercise sessions, laps, and individual pool lengths. ```APIDOC ## FITSessionMesg and FITLapMesg — Activity structure messages `FITSessionMesg` summarizes one continuous exercise session (sport, duration, distance, laps). `FITLapMesg` summarizes one lap within a session. Both share a similar field set and are typically written once after all `FITRecordMesg` and `FITEventMesg` entries. For swim activities, `FITLengthMesg` models each pool length within a lap. ```swift import ObjcFIT // Session for a 500 m pool swim let session = FITSessionMesg() session.setMessageIndex(0) session.setTimestamp(FITDate()) session.setStartTime(FITDate()) session.setSport(FITSportSwimming) session.setSubSport(FITSubSportLapSwimming) session.setTotalElapsedTime(840) // 14 minutes in seconds session.setTotalTimerTime(840) session.setTotalDistance(500) // metres session.setPoolLength(25.0) // metres session.setPoolLengthUnit(FITDisplayMeasureMetric) session.setNumLengths(20) session.setNumActiveLengths(20) session.setTotalStrokes(400) session.setFirstLapIndex(0) session.setNumLaps(1) // Lap for first 250 m let lap = FITLapMesg() lap.setMessageIndex(0) lap.setStartTime(FITDate()) lap.setTimestamp(FITDate()) lap.setTotalElapsedTime(420) lap.setTotalDistance(250) lap.setSport(FITSportSwimming) lap.setSubSport(FITSubSportLapSwimming) lap.setNumLengths(10) lap.setNumActiveLengths(10) // Individual pool length let length = FITLengthMesg() length.setMessageIndex(0) length.setStartTime(FITDate()) length.setTotalElapsedTime(42.0) // seconds length.setTotalTimerTime(42.0) length.setLengthType(FITLengthTypeActive) length.setSwimStroke(FITSwimStrokeFreestyle) length.setTotalStrokes(20) length.setAvgSwimmingCadence(FITUInt8((20.0 * 60) / 42.0)) // strokes/min print("Pool length avg speed: \(25.0 / 42.0) m/s") ``` ``` -------------------------------- ### Create FIT Session, Lap, and Length Messages Source: https://context7.com/garmin/fit-objective-c-sdk/llms.txt Example demonstrating the creation and population of FITSessionMesg, FITLapMesg, and FITLengthMesg objects for a pool swim activity. Ensure correct units and values are set for accurate data representation. ```swift import ObjcFIT // Session for a 500 m pool swim let session = FITSessionMesg() session.setMessageIndex(0) session.setTimestamp(FITDate()) session.setStartTime(FITDate()) session.setSport(FITSportSwimming) session.setSubSport(FITSubSportLapSwimming) session.setTotalElapsedTime(840) // 14 minutes in seconds session.setTotalTimerTime(840) session.setTotalDistance(500) // metres session.setPoolLength(25.0) // metres session.setPoolLengthUnit(FITDisplayMeasureMetric) session.setNumLengths(20) session.setNumActiveLengths(20) session.setTotalStrokes(400) session.setFirstLapIndex(0) session.setNumLaps(1) // Lap for first 250 m let lap = FITLapMesg() lap.setMessageIndex(0) lap.setStartTime(FITDate()) lap.setTimestamp(FITDate()) lap.setTotalElapsedTime(420) lap.setTotalDistance(250) lap.setSport(FITSportSwimming) lap.setSubSport(FITSubSportLapSwimming) lap.setNumLengths(10) lap.setNumActiveLengths(10) // Individual pool length let length = FITLengthMesg() length.setMessageIndex(0) length.setStartTime(FITDate()) length.setTotalElapsedTime(42.0) // seconds length.setTotalTimerTime(42.0) length.setLengthType(FITLengthTypeActive) length.setSwimStroke(FITSwimStrokeFreestyle) length.setTotalStrokes(20) length.setAvgSwimmingCadence(FITUInt8((20.0 * 60) / 42.0)) // strokes/min print("Pool length avg speed: \(25.0 / 42.0) m/s") ``` -------------------------------- ### Create and Write a .fit file with FITEncoder Source: https://context7.com/garmin/fit-objective-c-sdk/llms.txt Use FITEncoder to create a new .fit file. The file must start with a FITFileIdMesg and end with a FITActivityMesg. The encoder handles writing the file header and calculating the CRC. ```swift import ObjcFIT let encoder = FITEncoder(version: .V20) let filePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/myActivity.fit" guard encoder.open(filePath) else { fatalError("Could not open file") } // Every FIT file MUST start with a FileId message let startTime = FITDate() let fileId = FITFileIdMesg() fileId.setType(FITFileActivity) fileId.setManufacturer(FITManufacturerDevelopment) fileId.setProduct(0) fileId.setTimeCreated(startTime) fileId.setSerialNumber(UInt32.random(in: 1..