Skip to content

Instantly share code, notes, and snippets.

@regularberry
Created September 25, 2020 19:45
Show Gist options
  • Save regularberry/f1d7e9afef8aff4d63493a0ba12d1b56 to your computer and use it in GitHub Desktop.
Save regularberry/f1d7e9afef8aff4d63493a0ba12d1b56 to your computer and use it in GitHub Desktop.
func printJSON() {
let rootContext = Context(
data: Context.Data(
displayOrder: 0,
identifierPath: [Bundle.main.bundleIdentifier ?? ""],
isAssignable: false,
progressReportingCapabilities: [],
summary: "Fun tapper games for math and writing!",
title: "EduJam",
topic: "",
type: "app"
),
metadata: Context.Metadata(
keywords: ["math", "writing", "game"]
)
)
let gameContexts: [Context] = // convert your activities to the JSON-friendly Context
let node = ContextsRequest(contexts: [rootContext] + gameContexts)
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let jsonData = (try? encoder.encode(node)) ?? Data()
let jsonStr = String(data: jsonData, encoding: .utf8) ?? ""
print(jsonStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment