Skip to content

Commit 7537289

Browse files
committed
Add Graph+Debug API
1 parent 40b020c commit 7537289

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Graph+Debug.swift
3+
// OpenGraphShims
4+
5+
// FIXME: Update name in OpenGraph
6+
public typealias Graph = OGGraph
7+
public typealias Subgraph = OGSubgraph
8+
9+
#if canImport(Darwin)
10+
11+
import Foundation
12+
13+
@_spi(Debug)
14+
extension Graph {
15+
public var dict: [String: Any]? {
16+
let options = ["format": "graph/dict"] as NSDictionary
17+
guard let description = Graph.description(nil, options: options) else {
18+
return nil
19+
}
20+
guard let dictionary = description.takeUnretainedValue() as? NSDictionary else {
21+
return nil
22+
}
23+
return dictionary as? [String: Any]
24+
}
25+
26+
// style:
27+
// - bold: empty input/output edge
28+
// - dashed: indirect or has no value
29+
// color:
30+
// - red: is_changed
31+
public var dot: String? {
32+
let options = ["format": "graph/dot"] as NSDictionary
33+
guard let description = Graph.description(self, options: options)
34+
else {
35+
return nil
36+
}
37+
return description.takeUnretainedValue() as? String
38+
}
39+
}
40+
41+
#endif

0 commit comments

Comments
 (0)