You can take certain utility network A utility network is a feature service that represents a utility system, such as water, gas, or electricity. A utility network provides the capabilities to visualize, edit, and analyze utility assets and data. Learn more information offline Offline is the state of having no network connection and applications cannot access ArcGIS Online or ArcGIS Enterprise. Learn more . Associations An association is a relationship between two elements that is reflected in a utility network topology. Learn more , which are used to describe containment, structural attachment, and connection between features with non-coincident geometry, can be queried and displayed with offline data Offline data is data that is generated and downloaded from a feature service, vector tile service, or image tile service for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more . Simple edits can also be made to utility network features while offline and synchronized back to ArcGIS Enterprise ArcGIS Enterprise is a GIS mapping, analytics, data hosting, and content management product that can be hosted on-premise or in a cloud infrastructure. It includes software, applications, tools, APIs, and services for users and developers. Learn more .

The following code takes a web map offline that contains a utility network. The utility network tables are automatically synced with a map when a utility network is detected within.

25 collapsed lines
import SwiftUI
import ArcGIS
private class Model: ObservableObject {
let map: Map = {
// The URL must be to a web map hosted on ArcGIS Enterprise 10.9 or later.
let map = Map(url: URL(string: "https://myserver.esri.com/portal/home/item.html?id=myPortalID")!)!
return map
}()
// The offline map task.
var offlineMapTask: OfflineMapTask?
// The generate offline map job.
@Published var generateOfflineMapJob: GenerateOfflineMapJob!
// Creates a temporary directory.
private func makeTemporaryDirectory() -> URL {
// swiftlint:disable:next force_try
try! FileManager.default.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: Bundle.main.bundleURL,
create: true
)
}
func initializeOfflineMapTask() async {
do {
try await map.load()
// Creates the offline map task with the web map.
offlineMapTask = OfflineMapTask(onlineMap: map)
await makeGenerateOfflineMapJob()
} catch {
print("Error loading map.")
}
}
func makeGenerateOfflineMapJob() async {
let areaOfInterest = Envelope(xMin: -13049000, yMin: 3861000, xMax: -13048000, yMax: 3861500, spatialReference: map.spatialReference)
// Creates the default parameters for the offline map task.
guard let parameters = await makeGenerateParameters(areaOfInterest: areaOfInterest) else { return }
// Creates the generate offline map job based on the parameters.
guard let offlineMapTask = offlineMapTask else { return }
generateOfflineMapJob = offlineMapTask.makeGenerateOfflineMapJob(
parameters: parameters,
downloadDirectory: makeTemporaryDirectory()
)
// Starts the offline map job.
generateOfflineMapJob.start()
do {
// Awaits the output of the job.
let output = try await generateOfflineMapJob.output
// Gets the first utility network in the offline map.
let utilityNetwork = output.offlineMap.utilityNetworks.first
try await utilityNetwork?.load()
} catch {
print("Error getting first utility network.")
}
}
func makeGenerateParameters(areaOfInterest: Envelope) async -> GenerateOfflineMapParameters? {
do {
// Retrieves the default offline map parameters for an area of interest.
let parameters = try await offlineMapTask?.makeDefaultGenerateOfflineMapParameters(areaOfInterest: areaOfInterest)
parameters?.includesBasemap = false
return parameters
} catch {
print("Error generating parameters.")
return nil
}
}
11 collapsed lines
}
struct OfflineMapUNView: View {
// An `ObservableObject` data model that contains a map.
@StateObject private var model = Model()
var body: some View {
MapView(map: model.map)
}
}

The following code takes a utility network offline using a service geodatabase. The utility network tables only get synced when the sync mode in the generate geodatabase parameters is set to sync system tables.

25 collapsed lines
import SwiftUI
import ArcGIS
private class Model: ObservableObject {
let map: Map = {
// The URL must be to a web map hosted on ArcGIS Enterprise 10.9 or later.
let map = Map(url: URL(string: "https://myserver.esri.com/portal/home/item.html?id=myPortalID")!)!
return map
}()
// The geodatabase sync task.
var geodatabaseSyncTask: GeodatabaseSyncTask?
// The generate offline geodatabase job.
@Published var generateGeodatabaseJob: GenerateGeodatabaseJob!
// Creates a temporary directory.
private func makeTemporaryDirectory() -> URL {
// swiftlint:disable:next force_try
try! FileManager.default.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: Bundle.main.bundleURL,
create: true
)
}
func initializeGeodatabaseSyncTask() async {
do {
try await map.load()
// The URL must be to a feature service hosted on ArcGIS Enterprise 10.9 or later.
let featureServiceURL = URL(string: "https://myserver.esri.com/server/rest/services/SDKTest/FeatureServer")!
geodatabaseSyncTask = GeodatabaseSyncTask(url: featureServiceURL)
await makeGenerateGeodatabaseJob()
} catch {
print("Error initializing geodatabase sync task.")
}
}
func makeGenerateGeodatabaseJob() async {
// Makes the default parameters with the area of interest.
let areaOfInterest = Envelope(xMin: 473240, yMin: 3600000, xMax: 475000, yMax: 3605000, spatialReference: .init(wkid: WKID(26911)!))
guard let parameters = await makeDefaultParameters(areaOfInterest: areaOfInterest) else { return }
parameters.utilityNetworkSyncMode = .syncSystemTables
// Creates a temporary directory to store the downloaded geodatabase.
let downloadDirectory = makeTemporaryDirectory()
generateGeodatabaseJob = geodatabaseSyncTask?.makeGenerateGeodatabaseJob(parameters: parameters, downloadFileURL: downloadDirectory)
// Starts the geodatabase.
generateGeodatabaseJob.start()
do {
// Prints the geodatabase's first utility network.
let output = try await generateGeodatabaseJob.output
guard let utilityNetwork = output.utilityNetworks.first else { return }
print(utilityNetwork.name)
} catch {
print("Error getting first utility network.")
return
}
}
// Makes the default parameters with the area of interest.
func makeDefaultParameters(areaOfInterest: Envelope) async -> GenerateGeodatabaseParameters? {
do {
return try await geodatabaseSyncTask?.makeDefaultGenerateGeodatabaseParameters(extent: areaOfInterest)
} catch {
return nil
}
}
13 collapsed lines
}
struct OfflineFeatureServiceView: View {
// An `ObservableObject` data model that contains a map.
@StateObject private var model = Model()
var body: some View {
MapView(map: model.map)
.task {
await model.initializeGeodatabaseSyncTask()
}
}
}

For more information about offline workflows using ArcGIS Maps SDKs for Native Apps, see the Offline maps, scenes, and data topic.