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
| Manual Generation | LLM Generation |
|---|---|
manual.mp4 |
llm.mov |
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.
Add the HealthKitDataGenerator package to your project:
dependencies: [
.package(url: "https://github.com/aminbenarieb/healthkit-data-generator", from: "1.0.0")
]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)// 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)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.
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)Apple Foundation Model (iOS 26.0+): Native integration with Apple's on-device AI model
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.
This project is licensed under the MIT License - see the LICENSE file for details.