Skip to content
DICOM Parser for Swift
Swift Other
  1. Swift 98.3%
  2. Other 1.7%
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Resources/DICOM Definitions


CI Status Version License Platform


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

pod 'DCDicom'


Lasse Porsch,


DCDicom is available under the MIT license. See the LICENSE file for more info.


Creating a DicomObject

You can create a DicomObject instance from a URL, from Data or from any InputStream.

do {
    let dicomObjectFromURL = try DicomObject(url: dicomURL)
    let dicomObjectFromData = try DicomObject(data: dicomData)
    let dicomObjectFromInputStream = try DicomObject(inputStream: dicomInputStream)
} catch {
    print("Something went wrong! Error: \(error)")

Reading the Data Elements

DICOMs are hierarchical data structures consisting of Data Elements. Once a DicomObject is instantiated, you have direct access to all of its root-level data elements by traversing the dataElements:

dicomObject.dataElements.forEach {
    print("Found DataElement with \($0.tag)")

Specific Data Elements can also be accessed by subscript:

let sopInstanceUidDataElement = dicomObject[0x00080018]!

Accessing typed values

While each Data Element normally has a raw value of type Data and most have a string representation of this raw value, you can also "introspect" the actual" data type of the Data Element and get a Swift-typed value. The Data Element's Value Representation is used for this. However, it is only available if it is explicitly mentioned in the DICOM object. If the Dicom Object uses implicit Value Representations, you have to manually convert the raw data into a typed value based on the semantics of the specific Dicom Object as per the corresponding DICOM Conformance Statement.

guard let vr = dataElement.vr else {
    print("Implicit Value Representation. Cannot determine value type without more context")
switch vr {
    case .FD: // Double
        if let doubleValue = (dataElement as! DicomDataElementFD).value {
            print(String(format: "Double value = %f", doubleValue))
        } else {
            print("Empty value")
    case .FL: // Float
        if let floatValue = (dataElement as! DicomDataElementFL).value {
            print(String(format: "Float value = %f", floatValue))
        } else {
            print("Empty value")
    case .DA: // Date
        if let dateValue = (dataElement as! DicomDataElementDA).value {
            let formatter = DateFormatter()
            formatter.dateStyle = .full
            print(String(format: "Date value = %@", formatter.string(from: dateValue)))
        } else {
            print("Empty value")
You can’t perform that action at this time.