Skip to content

Commit 4514841

Browse files
committed
RUM-8415 Replace Reflector with ReflectionMirror
1 parent e2e4929 commit 4514841

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

DatadogInternal/Sources/Utils/ReflectionMirror.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ extension ReflectionMirror {
247247
return descendant(paths: &paths)
248248
}
249249

250-
func descendant(_ paths: [Path]) -> Any? {
250+
public func descendant(_ paths: [Path]) -> Any? {
251251
var paths = paths
252252
return descendant(paths: &paths)
253253
}

DatadogRUM/Sources/Instrumentation/Views/SwiftUI/SwiftUIViewNameExtractor.swift

+3-18
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,12 @@ internal struct SwiftUIReflectionBasedViewNameExtractor: SwiftUIViewNameExtracto
2020

2121
init(
2222
reflectorFactory: @escaping (Any) -> TopLevelReflector = { subject in
23-
Reflector(
24-
subject: subject,
25-
// MARK: TODO: RUM-9035 - Telemetry
26-
telemetry: NOPTelemetry()
27-
)
23+
ReflectionMirror(reflecting: subject)
2824
}
2925
) {
3026
self.createReflector = reflectorFactory
3127
}
3228

33-
/// Convenience initializer
34-
init(telemetry: Telemetry) {
35-
self.init(reflectorFactory: { subject in
36-
Reflector(subject: subject, telemetry: telemetry)
37-
})
38-
}
39-
4029
/// Attempts to extract a meaningful SwiftUI view name from a `UIViewController`
4130
/// - Parameter viewController: The `UIViewController` potentially hosting a SwiftUI view
4231
/// - Returns: The extracted view name or `nil` if extraction failed
@@ -105,11 +94,7 @@ internal struct SwiftUIReflectionBasedViewNameExtractor: SwiftUIViewNameExtracto
10594

10695
// MARK: - Helpers
10796
private static let genericTypePattern: NSRegularExpression? = {
108-
do {
109-
return try NSRegularExpression(pattern: #"<(?:[^,>]*,\s+)?([^<>,]+?)>"#)
110-
} catch {
111-
return nil
112-
}
97+
return try? NSRegularExpression(pattern: #"<(?:[^,>]*,\s+)?([^<>,]+?)>"#)
11398
}()
11499

115100
/// Extracts a view name from a type description
@@ -140,7 +125,7 @@ internal struct SwiftUIReflectionBasedViewNameExtractor: SwiftUIViewNameExtracto
140125
}
141126

142127
let selectedIndex = parent.selectedIndex
143-
let containerReflector = Reflector(subject: container, telemetry: NOPTelemetry())
128+
let containerReflector = ReflectionMirror(reflecting: container)
144129

145130
if let output = SwiftUIViewPath.hostingController.traverse(with: containerReflector) {
146131
let typeName = typeDescription(of: output)

DatadogRUM/Sources/Instrumentation/Views/SwiftUI/TopLevelReflector.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ internal protocol TopLevelReflector {
1616
}
1717

1818
// MARK: - Reflector
19-
extension Reflector: TopLevelReflector {}
19+
extension ReflectionMirror: TopLevelReflector {}

0 commit comments

Comments
 (0)