Skip to content

Commit 7da0415

Browse files
authored
Merge pull request #541 from Esri/df/buildFix_redo
[Fix] Samples unavailable on Mac Catalyst
2 parents 49cdfc0 + b750b72 commit 7da0415

File tree

9 files changed

+53
-20
lines changed

9 files changed

+53
-20
lines changed

Scripts/GenerateSampleViewSourceCode.swift

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ private let sampleMetadata: [SampleMetadata] = {
111111
exit(1)
112112
}
113113
}
114-
.sorted { $0.title < $1.title }
115114
} catch {
116115
print("error: Decoding Samples: \(error.localizedDescription)")
117116
exit(1)
@@ -123,6 +122,7 @@ private let sampleStructs = sampleMetadata
123122
let portalItemIDs = (sample.offlineData ?? [])
124123
.map { #"PortalItem.ID("\#($0)")!"# }
125124
return """
125+
\(sample.category == "Augmented Reality" ? "@available(macCatalyst, unavailable)" : "")
126126
struct \(sample.structName): Sample {
127127
var name: String { \"\(sample.title)\" }
128128
var category: String { \"\(sample.category)\" }
@@ -136,25 +136,44 @@ private let sampleStructs = sampleMetadata
136136
}
137137
.joined(separator: "\n")
138138

139-
private let entries = sampleMetadata
139+
// The set of samples supported on all supported platforms.
140+
private let commonSamples = sampleMetadata
141+
.filter { $0.category != "Augmented Reality" }
140142
.map { sample in "\(sample.structName)()" }
141-
.joined(separator: ",\n ")
142-
private let arrayRepresentation = """
143+
.joined(separator: ",\n ")
144+
145+
// The set of samples supported only on iOS.
146+
private let iOSSpecificSamples = sampleMetadata
147+
.filter { $0.category == "Augmented Reality" }
148+
.map { sample in "\(sample.structName)()" }
149+
.joined(separator: ",\n ")
150+
151+
private let commonSamplesArrayRepresentation = """
143152
[
144-
\(entries)
145-
]
146-
#if targetEnvironment(macCatalyst) || targetEnvironment(simulator)
147-
// Exclude AR samples from Mac Catalyst and Simulator targets
148-
// as they don't have camera and sensors available.
149-
.filter { $0.category != "Augmented Reality" }
153+
\(commonSamples)
154+
]
155+
"""
156+
157+
private let iOSSamplesArrayRepresentation = """
158+
{
159+
#if !targetEnvironment(macCatalyst) && !targetEnvironment(simulator)
160+
// Exclude AR samples from Mac Catalyst and Simulator targets
161+
// as they don't have camera and sensors available.
162+
[
163+
\(iOSSpecificSamples)
164+
]
165+
#else
166+
[]
150167
#endif
168+
}()
151169
"""
152170

153171
do {
154172
let templateFile = try String(contentsOf: templateURL, encoding: .utf8)
155173
// Replaces the empty array code stub, i.e. [], with the array representation.
156174
let content = templateFile
157-
.replacingOccurrences(of: "[/* samples */]", with: arrayRepresentation)
175+
.replacingOccurrences(of: "[/* common_samples */]", with: commonSamplesArrayRepresentation)
176+
.replacingOccurrences(of: "[/* ios_samples */]", with: iOSSamplesArrayRepresentation)
158177
.replacingOccurrences(of: "/* structs */", with: sampleStructs)
159178
try content.write(to: outputFileURL, atomically: true, encoding: .utf8)
160179
} catch {

Shared/Samples/Augment reality to collect data/AugmentRealityToCollectDataView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import ArcGISToolkit
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
struct AugmentRealityToCollectDataView: View {
2021
/// The view model for this sample.
2122
@StateObject private var model = Model()
@@ -98,6 +99,7 @@ struct AugmentRealityToCollectDataView: View {
9899
}
99100
}
100101

102+
@available(macCatalyst, unavailable)
101103
private extension AugmentRealityToCollectDataView {
102104
@MainActor
103105
class Model: ObservableObject {
@@ -176,6 +178,7 @@ private extension AugmentRealityToCollectDataView {
176178
}
177179
}
178180

181+
@available(macCatalyst, unavailable)
179182
private extension AugmentRealityToCollectDataView {
180183
/// The health of a tree.
181184
enum TreeHealth: Int16, CaseIterable, Equatable {
@@ -196,7 +199,3 @@ private extension AugmentRealityToCollectDataView {
196199
}
197200
}
198201
}
199-
200-
#Preview {
201-
AugmentRealityToCollectDataView()
202-
}

Shared/Samples/Augment reality to fly over scene/AugmentRealityToFlyOverSceneView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import ArcGISToolkit
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
struct AugmentRealityToFlyOverSceneView: View {
2021
/// A scene with an imagery basemap, a world elevation source, and a mesh layer of Girona, Spain.
2122
@State private var scene: ArcGIS.Scene = {
@@ -58,7 +59,3 @@ private extension URL {
5859
.init(string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")!
5960
}
6061
}
61-
62-
#Preview {
63-
AugmentRealityToFlyOverSceneView()
64-
}

Shared/Samples/Augment reality to navigate route/AugmentRealityToNavigateRouteView.ARSceneView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ArcGISToolkit
1717
import AVFAudio
1818
import SwiftUI
1919

20+
@available(macCatalyst, unavailable)
2021
extension AugmentRealityToNavigateRouteView {
2122
/// A world scale scene view displaying route graphics from a given model.
2223
struct ARRouteSceneView: View {
@@ -84,6 +85,7 @@ extension AugmentRealityToNavigateRouteView {
8485
}
8586
}
8687

88+
@available(macCatalyst, unavailable)
8789
extension AugmentRealityToNavigateRouteView {
8890
// MARK: Scene Model
8991

Shared/Samples/Augment reality to navigate route/AugmentRealityToNavigateRouteView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import CoreLocation
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
struct AugmentRealityToNavigateRouteView: View {
2021
/// The view model for the map view in the sample.
2122
@StateObject private var model = MapModel()
@@ -99,6 +100,7 @@ struct AugmentRealityToNavigateRouteView: View {
99100
}
100101
}
101102

103+
@available(macCatalyst, unavailable)
102104
private extension AugmentRealityToNavigateRouteView {
103105
// MARK: Map Model
104106

Shared/Samples/Augment reality to show hidden infrastructure/AugmentRealityToShowHiddenInfrastructureView.ARSceneView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import ArcGISToolkit
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
extension AugmentRealityToShowHiddenInfrastructureView {
2021
/// A world scale scene view displaying pipe graphics from a given model.
2122
struct ARPipesSceneView: View {
@@ -67,6 +68,7 @@ extension AugmentRealityToShowHiddenInfrastructureView {
6768
}
6869
}
6970

71+
@available(macCatalyst, unavailable)
7072
extension AugmentRealityToShowHiddenInfrastructureView {
7173
// MARK: Scene Model
7274

Shared/Samples/Augment reality to show hidden infrastructure/AugmentRealityToShowHiddenInfrastructureView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import CoreLocation
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
struct AugmentRealityToShowHiddenInfrastructureView: View {
2021
/// The view model for the map view in the sample.
2122
@StateObject private var model = MapModel()
@@ -128,6 +129,7 @@ struct AugmentRealityToShowHiddenInfrastructureView: View {
128129
}
129130
}
130131

132+
@available(macCatalyst, unavailable)
131133
private extension AugmentRealityToShowHiddenInfrastructureView {
132134
// MARK: Map Model
133135

@@ -241,6 +243,7 @@ private extension AugmentRealityToShowHiddenInfrastructureView {
241243
}
242244
}
243245

246+
@available(macCatalyst, unavailable)
244247
private extension View {
245248
/// Presents an alert that allows the user to enter an elevation offset for a pipe.
246249
/// - Parameters:

Shared/Samples/Augment reality to show tabletop scene/AugmentRealityToShowTabletopSceneView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ArcGIS
1616
import ArcGISToolkit
1717
import SwiftUI
1818

19+
@available(macCatalyst, unavailable)
1920
struct AugmentRealityToShowTabletopSceneView: View {
2021
/// The scene used to create the scene view.
2122
@State private var scene = ArcGIS.Scene()

Shared/SamplesApp+Samples.swift.tache

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
import SwiftUI
1616

1717
extension SamplesApp {
18+
/// The common samples for this app.
19+
static var commonSamples: [Sample] {
20+
[/* common_samples */]
21+
}
22+
/// The iOS samples for this app.
23+
static var iOSSamples: [Sample] {
24+
[/* ios_samples */]
25+
}
1826
/// The samples for this app.
19-
static let samples: [Sample] = [/* samples */]
27+
static let samples = (commonSamples + iOSSamples).sorted { $0.name < $1.name }
2028
}
2129

2230
// MARK: Sample Structs

0 commit comments

Comments
 (0)