File tree Expand file tree Collapse file tree 3 files changed +38
-12
lines changed
Expand file tree Collapse file tree 3 files changed +38
-12
lines changed Original file line number Diff line number Diff line change 66// Status: WIP
77
88public import OpenGraph_SPI
9+ import Foundation
910
1011extension Graph {
1112 public static func typeIndex(
@@ -71,3 +72,27 @@ extension Graph {
7172 @inlinable
7273 public static func setOutputValue<Value>(_ value: UnsafePointer<Value>)
7374}
75+
76+ extension Graph {
77+ public func archiveJSON(name: String?) {
78+ let options: NSDictionary = [
79+ Graph.descriptionFormat: " graph/ dict" ,
80+ Graph.descriptionIncludeValues: true,
81+ ]
82+ guard let description = Graph.description(self, options: options) else { // FIXME
83+ return
84+ }
85+ var name = name ?? " graph"
86+ name. append ( " .ag-json " )
87+ let path = ( NSTemporaryDirectory ( ) as NSString ) . appendingPathComponent ( name)
88+ guard let data = try ? JSONSerialization . data ( withJSONObject: description, options: [ ] ) else {
89+ return
90+ }
91+ let url = URL ( fileURLWithPath: path)
92+ do {
93+ try data. write ( to: url, options: [ ] )
94+ print ( " Wrote graph data to \" \( path) \" . " )
95+ } catch {
96+ }
97+ }
98+ }
Original file line number Diff line number Diff line change @@ -37,18 +37,6 @@ OG_EXPORT
3737OG_REFINED_FOR_SWIFT
3838OGGraphRef OGGraphCreateShared (_Nullable OGGraphRef graph ) OG_SWIFT_NAME (OGGraphRef .init (shared :));
3939
40- OG_EXPORT
41- OG_REFINED_FOR_SWIFT
42- void OGGraphArchiveJSON (char const * _Nullable name ) OG_SWIFT_NAME (OGGraphRef .archiveJSON (name :));
43-
44- OG_EXPORT
45- OG_REFINED_FOR_SWIFT
46- void OGGraphArchiveJSON2 (char const * _Nullable name , uint8_t options ) OG_SWIFT_NAME (OGGraphRef .archiveJSON (name :options :));
47-
48- OG_EXPORT
49- OG_REFINED_FOR_SWIFT
50- _Nullable CFTypeRef OGGraphDescription (_Nullable OGGraphRef graph , CFDictionaryRef options ) OG_SWIFT_NAME (OGGraphRef .description (_ :options :));
51-
5240OG_EXPORT
5341OG_REFINED_FOR_SWIFT
5442CFTypeID OGGraphGetTypeID (void ) OG_SWIFT_NAME (getter :OGGraphRef .typeID ());
Original file line number Diff line number Diff line change 66#define OGGraphDescription_h
77
88#include "OGBase.h"
9+ #include "OGGraph.h"
910
1011OG_ASSUME_NONNULL_BEGIN
1112
@@ -29,6 +30,18 @@ static const CFStringRef OGDescriptionAllGraphs OG_SWIFT_NAME(OGGraphRef.descrip
2930
3031#endif
3132
33+ OG_EXPORT
34+ OG_REFINED_FOR_SWIFT
35+ void OGGraphArchiveJSON (char const * _Nullable name ) OG_SWIFT_NAME (OGGraphRef .archiveJSON (name :));
36+
37+ OG_EXPORT
38+ OG_REFINED_FOR_SWIFT
39+ void OGGraphArchiveJSON2 (char const * _Nullable name , uint8_t options ) OG_SWIFT_NAME (OGGraphRef .archiveJSON (name :options :));
40+
41+ OG_EXPORT
42+ OG_REFINED_FOR_SWIFT
43+ _Nullable CFTypeRef OGGraphDescription (_Nullable OGGraphRef graph , CFDictionaryRef options ) OG_SWIFT_NAME (OGGraphRef .description (_ :options :));
44+
3245OG_EXTERN_C_END
3346
3447OG_IMPLICIT_BRIDGING_DISABLED
You can’t perform that action at this time.
0 commit comments