Skip to content

Instantly share code, notes, and snippets.

View acwright's full-sized avatar

Aaron Wright acwright

View GitHub Profile
@acwright
acwright / DocExampleApp.swift
Created July 26, 2020 20:01
DocExampleApp.swift
var body: some Scene {
DocumentGroup(newDocument: {
DocExampleDocument()
}) { file in
ContentView(document: file.document)
}
}
@acwright
acwright / DocExampleDocument3.swift
Created July 26, 2020 19:57
DocExampleDocument.swift
@Published var text: String
@acwright
acwright / DocExampleDocument2.swift
Last active July 26, 2020 19:44
DocExample ReferenceFileDocument protocol methods
func snapshot(contentType: UTType) throws -> String {
return self.text
}
func write(snapshot: String, to fileWrapper: inout FileWrapper, contentType: UTType) throws {
let data = snapshot.data(using: .utf8)!
fileWrapper = FileWrapper(regularFileWithContents: data)
}
@acwright
acwright / DocExampleDocument.swift
Created July 26, 2020 19:32
DocExampleDocument.swift
class DocExampleDocument: ReferenceFileDocument {
// ...
}
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
var statusBarItem: NSStatusItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
@acwright
acwright / introducingpinball2.swift
Last active December 9, 2019 08:42
Introducing Pinball 2
try? URLSession.shared.dataTask(for: endpoint) { (data, response, error) in
// Do something with the response…
}
// Or using Combine…
if #available(OSX 10.15, *) {
let publisher = try? URLSession.shared.dataTaskPublisher(for: endpoint)
// Do something with the Combine Publisher
@acwright
acwright / introducingpinball1.swift
Last active December 9, 2019 08:35
Introducing Pnball 1
let endpoint = Pinball.Endpoint(
method: .get,
host: 'baconipsum.com',
paths: ["api"],
queries: [
Pinball.Query(key: "type", value: "meat-and-filler")
]
)