Fhir models for swift




Minimal FHIR standard models and data types for iOS

CocoaPods Compatible Carthage Compatible Swift Package Manager compatible License


fastlane is used to manage fhir-parser and integrate generated models into Xcode project

fhir-parser is used to generate Swift models from JSON examples for latest FHIR standard

Swift-FHIR was used as inspiration for this project

Apple-FHIR R4 models were (tepmorarily) ported over because we needed a pod version of it

Required resources include:

  • Base classes for primitive data types
  • Rules and templates for mapping
  • Settings with custom profiles and build targets

Note: Check parser-resources for more info





To install with CocoaPods add the following lines (according to which model version you use) to the podfile.

source 'https://github.com/d4l-data4life/d4l-cocoapods-specs.git'

pod 'Data4LifeFHIR', '~> 0.18.0'
pod 'ModelsR4', '~> 0.18.0'

Note: For more info check README.


To install with Carthage add the following line to the Cartfile:

github "d4l-data4life/d4l-utils-ios"

Run carthage to build the framework and drag the built Data4LifeFHIR.framework and/or ModelsR4.framework into your Xcode project. Follow build instructions.

Swift Package Manager

To install with Swift Package Manager add this package as a dependency in Package.swift:

.package(url: "https://github.com/d4l-data4life/d4l-fhir-ios.git", .upToNextMinor(from: "0.18.0"))


Install dependencies

bundler install

Install Carthage

brew install carthage

Note: For other installation methods check README.

Install Sourcery

brew install sourcery

Note: For other installation methods check README.

Build frameworks

Note: Since from XCode 12 Carthage packaging does not work anymore, please use the script.

./wcarthage.sh bootstrap --use-ssh --platform iOS

Generating models

Static files

These directories are not generated and are not meant to be removed from the project. They include FHIR DateTime encoding/tests and helpers/tests for contained resources.

  • FhirStu3/Sources/Helpers
  • FhirStu3/Tests/Helpers
  • FhirStu3/Tests/PrimitiveTests
  • FhirR4

Generate stu3 models and embed into Xcode project

  1. Run fastlane to generate STU3 models, R4 helpers and R4 tests
fastlane generate_all

Note: It's possible to generated separately STU3 Models, R4 helpers or R4 tests, check Fastlane README for more information


FHIR Stu3 standard

  • String / Integer / Decimal / Bool / URL / Base64Binary should inherit Element
  • All properties dealing with binary data are represented as base64 String
  • R4 Models are currently copied and pasted from Apples framework because of incompatibilty with Cocoapods (a podspec cant distribute contained swift packages)
  • R4 Models are missing keypaths and NSCopying support yet