All Projects → FitnessKit → FitDataProtocol

FitnessKit / FitDataProtocol

Licence: MIT License
Swift Implementation the Garmin Flexible and Interoperable Data Transfer Protocol.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to FitDataProtocol

SwiftZip
Swift wrapper for libzip — library for reading, creating, and modifying zip archives.
Stars: ✭ 44 (+37.5%)
Mutual labels:  swift-package-manager, spm
danger-swift-xcodesummary
A Danger-Swift plugin that adds build errors, warnings and unit tests results generated from xcodebuild to your Danger report
Stars: ✭ 72 (+125%)
Mutual labels:  swift-package-manager, spm
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+115.63%)
Mutual labels:  swift-package-manager, spm
Table
CLI tables in Swift
Stars: ✭ 53 (+65.63%)
Mutual labels:  swift-package-manager, spm
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-65.62%)
Mutual labels:  swift-package-manager, spm
SwiftDown
📦 A themable markdown editor component for your SwiftUI apps.
Stars: ✭ 203 (+534.38%)
Mutual labels:  swift-package-manager, spm
Ether
A Command-Line Interface for the Swift Package Manager
Stars: ✭ 86 (+168.75%)
Mutual labels:  swift-package-manager, spm
extensions-kit
📦 Collection of Swift+Apple Frameworks extensions for speeding up software development [iOS & iPadOS].
Stars: ✭ 71 (+121.88%)
Mutual labels:  swift-package-manager, spm
ecs
A dependency free, lightweight, fast Entity-Component System (ECS) implementation in Swift
Stars: ✭ 79 (+146.88%)
Mutual labels:  swift-package-manager, spm
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (-21.87%)
Mutual labels:  swift-package-manager, spm
CSV
A simple CSV file parser and serializer
Stars: ✭ 31 (-3.12%)
Mutual labels:  swift-package-manager, spm
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-53.12%)
Mutual labels:  swift-package-manager, spm
SupportEmail
Pre-populates emails with support information in iOS/iPadOS apps
Stars: ✭ 20 (-37.5%)
Mutual labels:  swift-package-manager, spm
Match3Kit
Library for simple Match3 games.
Stars: ✭ 38 (+18.75%)
Mutual labels:  swift-package-manager, spm
swift-watch
Watches over your Swift project's source
Stars: ✭ 43 (+34.38%)
Mutual labels:  swift-package-manager, spm
ecs-demo
Minimal demo App for the Fireblade Entity-Component System (ECS)
Stars: ✭ 20 (-37.5%)
Mutual labels:  swift-package-manager, spm
Flexcolorpicker
Modern color picker library written in Swift 5 that can be easily extended and customized. It aims to provide great UX and performance with stable, quality code.
Stars: ✭ 164 (+412.5%)
Mutual labels:  swift-package-manager, spm
Aksidemenu
Beautiful iOS side menu library with parallax effect. Written in Swift
Stars: ✭ 216 (+575%)
Mutual labels:  swift-package-manager, spm
YMFF
Feature management made easy.
Stars: ✭ 26 (-18.75%)
Mutual labels:  swift-package-manager, spm
SwiftSimctl
Swift client-server tool to call xcrun simctl from your simulator. Automate push notification testing!
Stars: ✭ 50 (+56.25%)
Mutual labels:  swift-package-manager, spm

FitDataProtocol

Swift5.2 Version License Platform

Swift Version of the Garmin Flexible and Interoperable Data Transfer Protocol.

Supports SDK Revision 21.16.0

Installation

FitDataProtocol is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'FitDataProtocol'

Swift Package Manager:

    dependencies: [
        .package(url: "https://github.com/FitnessKit/FitDataProtocol", from: "2.1.2")
    ]

How to Use

Decoding FIT Files

let fileUrl = URL(fileURLWithPath: "WeightScaleMultiUser" + ".fit")
let fileData = try? Data(contentsOf: fileUrl)

if let fileData = fileData {
    var decoder = FitFileDecoder(crcCheckingStrategy: .throws)

    do {

        try decoder.decode(data: fileData,
                           messages: FitFileDecoder.defaultMessages,
                           decoded: { (message: FitMessage) in

            print("Got Message: \(message)")

            if let message = message as? FileIdMessage {
                print("mssage", message.deviceSerialNumber)
            }

            if let message = message as? RecordMessage {
                records.append(message)
            }

            if let message = message as? SportMessage {
                sports.append(message)
            }

            if let message = message as? ActivityMessage {
                activity.append(message)
            }
        })

    } catch {
        print(error)
    }
}

Encoding FIT Files

As part of the Encoding of the FIT Files you can check for Validity of the data you are encoding.

The options are

  • none - No Validity Checks are done
  • fileType - Based on the File Type, checks will be done to insure correct fields are included
  • garminConnect - Special Check for creating FIT files for GarminConnect

Example:

let activity = ActivityMessage(timeStamp: FitTime(date: Date()),
                               totalTimerTime: nil,
                               localTimeStamp: nil,
                               numberOfSessions: nil,
                               activity: Activity.multisport,
                               event: nil,
                               eventType: nil,
                               eventGroup: nil)


let fieldId = FileIdMessage(deviceSerialNumber: nil,
                            fileCreationDate: time,
                            manufacturer: Manufacturer.garmin,
                            product: nil,
                            fileNumber: nil,
                            fileType: FileType.activity,
                            productName: nil)

let encoder = FitFileEncoder(dataValidityStrategy: .none)

let result = encoder.encode(fildIdMessage: fiel, messages: [activity])
switch result {
case .success(let encodedData):
    print(encodedData as NSData)
    /// you can save off the file data
case .failure(let error):
    print(error.localizedDescription)
}

///
/// You can still use doCatch 
///
do {
    let encoder = FitFileEncoder(dataValidityStrategy: .none)

    let data = try encoder.encode(fildIdMessage: fieldId, messages: [activity]).get()
    print(data as NSData)

    /// you can save off the file data

} catch  {
    print(error)
}

Author

This package is developed and maintained by Kevin A. Hoogheem

License

FitDataProtocol is available under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].