Your Company

Fork API for health data

Fork Swift SDK is a library on top of HealthKit that helps with the data extraction and normalisation.

App.swift
StepsView.swift
    func loadStepsData() {
        
    if let forkConnection = forkConnection {
        ForkSDK.shared.ensurePermissionsAreGranted(for: Set(
            [
                ForkDataTypes.steps,
            ]
        ),
         completion: { result in
            switch result {
            case .success(let hasPermissions):

                if hasPermissions {
                    
                    let today = Date()
                    let weekAgo = Calendar.current.date(byAdding: .day, value: -13, to: today)

                    // Get Weekly Steps
                    forkConnection.extractData(
                        ForkDataTypes.steps,
                        from: weekAgo,
                        to: today
                    ) { result in
                        switch result {
                        case .success(let data):
                            self.steps = data.data
                        case .failure(let error):
                            Log("Error: \(error)", onLevel: .error)
                        }
                    }
                } else {
                    Log("HealthKit permissions denied", onLevel: .warn)
                }
            case .failure(_):
                self.hasHealthKitPermissions = false
                Log("Error getting HeelthKit permissions", onLevel: .warn)
            }
        })
    }
}