Skip to content

aminbenarieb/healthkit-data-generator

Repository files navigation

HealthKit Data Generator

CI License: MIT Tuist Preview

Overview

HealthKitDataGenerator is a comprehensive Swift package that provides tools for:

  • Data Generation: Create realistic sample health data for testing
  • Data Export: Export HealthKit data to JSON format with flexible configuration
  • Data Import: Import health data from JSON profiles into HealthKit

Why use this?

  • Seed HealthKit with realistic data in minutes
  • Perfect for screenshots, demos, UI tests, and QA
  • AI-powered configs: “Create 2 weeks of marathon training” → ready-to-use samples

Demo Videos

Manual Generation LLM Generation
manual.mp4
llm.mov

Acknowledgments

This project is inspired by and builds upon the excellent work done in healthkit-sample-generator by Michael Seemann. While this SPM package is a complete rewrite with modern Swift features, LLM integration, and enhanced functionality, we acknowledge the foundational concepts and approaches from the original project.

Installation

Swift Package Manager

Add the HealthKitDataGenerator package to your project:

dependencies: [
    .package(url: "https://github.com/aminbenarieb/healthkit-data-generator", from: "0.1.0")
]

Building the app

This project uses Tuist. Refer to their website to install it, then run tuist generate.

Usage

Preset Profiles

import HealthKitDataGenerator
import HealthKit

let healthStore = HKHealthStore()
let generator = HealthKitDataGenerator(healthStore: healthStore)

// Generate 7 days of data with sporty profile
let config = SampleGenerationConfig(
    profile: .sporty,
    dateRange: .lastDays(7)
)

let allTypes = HealthKitConstants.authorizationWriteTypes()
try generator.generateAndPopulate(samplesTypes: allTypes, config: config)

Quick Presets

// Last week - sporty profile
let config1 = SampleGenerationConfig.lastWeekSporty()

// Last month - balanced profile
let config2 = SampleGenerationConfig.lastMonthBalanced()

// Last week - stressed profile
let config3 = SampleGenerationConfig.lastWeekStressed()

try generator.generateAndPopulate(samplesTypes: allTypes, config: config1)

Comprehensive Examples

This repository includes a SwiftUI demo app (HealthKitDataGeneratorApp/) showcasing all package features with an intuitive interface for both manual and AI-powered health data generation.

For detailed usage examples covering all features, see USAGE_EXAMPLES.md which includes custom profiles, date ranges, metric selection, generation patterns, LLM integration, and app integration examples.

🤖 AI-Powered Health Data Generation

The LLMManager enables AI-powered health data generation from natural language descriptions. It supports multiple LLM providers through a unified interface and automatically routes requests to the best available provider.

import HealthKitDataGenerator
import HealthKit

let healthStore = HKHealthStore()
let llmManager = LLMManager()

// Generate health data from natural language
let response = try await llmManager.generateHealthConfig(from: 
    "Create 2 weeks of marathon training data for an athlete with high activity, excellent sleep, and high-protein diet"
)

// Import the generated configuration
let generator = HealthKitDataGenerator(healthStore: healthStore)
try generator.importFromLLMJSON(response.json)

Current LLM Provider

Apple Foundation Model (iOS 26.0+): Native integration with Apple's on-device AI model

Extending with Custom Providers

You can add custom LLM providers by implementing the LLMProvider protocol:

class CustomLLMProvider: LLMProvider {
    let identifier = "custom_provider"
    let name = "Custom LLM"
    var isAvailable: Bool { true }
    
    func generateHealthConfig(from prompt: String) async throws -> String {
        // Your custom LLM integration
        return generatedJSON
    }
    
    func canHandle(_ prompt: String) -> Bool {
        // Determine if this provider can handle the request
        return true
    }
}

// Register your provider
llmManager.register(CustomLLMProvider())

The generated JSON follows the schema defined in LLM_JSON_SCHEMA.md, supporting both configuration-based generation and direct sample specification.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Swift Package for generating realistic HealthKit data with AI-powered natural language processing, custom profiles, and flexible configuration options for iOS development and testing.

Topics

Resources

License

Stars

Watchers

Forks

Contributors