Skip to content

Instantly share code, notes, and snippets.

View acwright's full-sized avatar

Aaron Wright acwright

View GitHub Profile
import SwiftUI
import CoreData
struct FetchedObjects<T, Content>: View where T : NSManagedObject, Content : View {
// MARK: - Properties
let content: ([T]) -> Content
var request: FetchRequest<T>
import SwiftUI
struct StudentsView: View {
@State var predicate: NSPredicate = NSPredicate(format: "firstName contains[c] %@", "Joe")
var body: some View {
VStack {
FetchedObjects(
predicate: self.predicate,
@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")
]
)
@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
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
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 popover: NSPopover!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
var statusBarItem: NSStatusItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
@acwright
acwright / DocExampleDocument.swift
Created July 26, 2020 19:32
DocExampleDocument.swift
class DocExampleDocument: ReferenceFileDocument {
// ...
}
@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)
}