Skip to content

List geodatabase versions

View on GitHub

Connect to a service and list versions of the geodatabase.

Image of List geodatabase versions sample

Use case

As part of a multi-user editing scenario, you can check with the server to see how many versions of the geodatabase are outstanding before syncing.

How to use the sample

When the sample loads, a list of geodatabase versions and their properties will be displayed.

How it works

  1. Create a geoprocessing task referring to a GPServer with a ListVersions task.
  2. Use the task to create default parameters.
  3. Use the created parameters to create a job.
  4. Run the job to get a geoprocessing result.
  5. Get a list of geoprocessing features from the Versions output parameter of the results.
  6. Format the geodatabase versions for display.

Relevant API

  • GeoprocessingFeatures
  • GeoprocessingJob
  • GeoprocessingParameters
  • GeoprocessingResult
  • GeoprocessingTask

About the data

The sample uses a sample geoprocessing service hosted on ArcGIS Online.

Additional information

ArcGIS Server does not include a geoprocessing service for listing geodatabase versions. You must configure one using the steps defined in Geoprocessing service example: list, create, and delete geodatabase versions in the ArcMap documentation.

Tags

conflict resolution, data management, database, multi-user, sync, version

Sample Code

ListGeodatabaseVersionsView.swift
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2025 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ArcGIS
import SwiftUI

struct ListGeodatabaseVersionsView: View {
    /// The analysis error shown in the error alert.
    @State private var analysisError: Error?
    /// The task used to perform geoprocessing jobs.
    @State private var geoprocessingTask = GeoprocessingTask(
        url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions")!
    )
    /// The geodatabase version information.
    @State private var geodatabaseVersionInfos: [GeodatabaseVersionInfo]?

    var body: some View {
        Form {
            if let geodatabaseVersionInfos {
                ForEach(geodatabaseVersionInfos, id: \.objectID) { version in
                    Section("OBJECTID: \(version.objectID)") {
                        LabeledContent("Name", value: version.name)
                            .lineLimit(1)
                            .textSelection(.enabled)
                        LabeledContent("Access", value: version.access)
                        LabeledContent("Created", value: version.created.formatted(date: .abbreviated, time: .shortened))
                        LabeledContent("Last Modified", value: version.lastModified.formatted(date: .abbreviated, time: .shortened))
                        LabeledContent("Is Owner", value: version.isOwner)
                        LabeledContent("Parent Version", value: version.parentVersionName)
                        if !version.description.isEmpty {
                            LabeledContent("Description", value: version.description)
                        }
                    }
                }
            } else {
                ProgressView()
                    .frame(maxWidth: .infinity)
            }
        }
        .task {
            do {
                let resultFeatures = try await fetchGeodatabaseVersions()
                geodatabaseVersionInfos = makeGeodatabaseVersionInfos(from: resultFeatures)
            } catch {
                analysisError = error
            }
        }
        .errorAlert(presentingError: $analysisError)
    }

    /// Fetches geodatabase versions using a geoprocessing job.
    private func fetchGeodatabaseVersions() async throws -> FeatureSet {
        // Creates and configures the job's parameters.
        let parameters = try await geoprocessingTask.makeDefaultParameters()

        // Creates and starts the job.
        let geoprocessingJob = geoprocessingTask.makeJob(parameters: parameters)
        geoprocessingJob.start()

        // Waits for the job to finish and retrieves the output.
        let result = try await withTaskCancellationHandler {
            try await geoprocessingJob.output
        } onCancel: {
            Task.detached {
                await geoprocessingJob.cancel()
            }
        }
        guard let versions = result.outputs["Versions"] as? GeoprocessingFeatures,
              let featureSet = versions.features else {
            fatalError("Expected geoprocessing results to contain 'Versions' output.")
        }
        return featureSet
    }

    /// Converts the features to an array of `GeodatabaseVersionInfo`.
    /// - Parameter featureSet: The features with version info from the job.
    /// - Returns: An array of `GeodatabaseVersionInfo`.
    private func makeGeodatabaseVersionInfos(from featureSet: FeatureSet) -> [GeodatabaseVersionInfo] {
        featureSet
            .features()
            .compactMap { version in
                GeodatabaseVersionInfo(from: version.attributes)
            }
            .sorted {
                $0.objectID < $1.objectID
            }
    }

    /// A structure representing geodatabase version information.
    private struct GeodatabaseVersionInfo {
        let objectID: Int64
        let name: String
        let access: String
        let created: Date
        let lastModified: Date
        let isOwner: String
        let parentVersionName: String
        let description: String

        init?(from dictionary: [String: Sendable]) {
            guard let access = dictionary["access"] as? String,
                  let created = dictionary["created"] as? Date,
                  let description = dictionary["description"] as? String,
                  let isOwner = dictionary["isowner"] as? String,
                  let lastModified = dictionary["lastmodified"] as? Date,
                  let name = dictionary["name"] as? String,
                  let objectID = dictionary["ObjectID"] as? Int64,
                  let parentVersionName = dictionary["parentversionname"] as? String else {
                return nil
            }

            self.objectID = objectID
            self.name = name
            self.access = access
            self.created = created
            self.lastModified = lastModified
            self.isOwner = isOwner
            self.parentVersionName = parentVersionName
            self.description = description
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.