Skip to content

Instantly share code, notes, and snippets.

View zentrope's full-sized avatar

Keith Irwin zentrope

  • Portland, Oregon
View GitHub Profile
@zentrope
zentrope / RichTextEditor.swift
Created October 2, 2022 00:00
NSTextView wrapper for SwiftUI
import Combine
import SwiftUI
struct RichTextEditor: NSViewRepresentable {
@Binding var attributedText: NSAttributedString
@Binding var showInspector: Bool
var activity: PassthroughSubject<Date, Never>
@zentrope
zentrope / main.swift
Created January 29, 2022 21:27
SwiftUI Toggle in menu items (macOS)
@main
struct TestApp: App {
@State var toggle = false
@State var other = true
var body: some Scene {
WindowGroup {
ContentView()
.frame(minWidth: 1000, minHeight: 600)
@zentrope
zentrope / DateView.swift
Created December 17, 2021 22:48
DateView SwiftUI component // example
//
// DateView.swift
//
import SwiftUI
struct DateView: View {
enum Format: String {
/// "MM-dd-yyyy hh:mm a"
@zentrope
zentrope / Login.swift
Last active December 3, 2021 23:26
Use enum to indicate state in SwiftUI
//
// ContentView.swift
// Test5
//
//import SwiftUI
//
//struct ContentView: View {
// var body: some View {
// Text("Hello, world!")
@zentrope
zentrope / locale.swift
Last active December 3, 2021 18:58
Pseudo example for locale picker
import SwiftUI
// Can be in another file
struct DataManager {
static let shared = DataManager()
static let defaultRegionCode = "US"
@zentrope
zentrope / ContentView.swift
Created November 26, 2021 21:40
Picker (like Mac's Contacts App) -- But there's no way to hide the background button style in SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
ContactEditor()
.frame(width: 500)
}
}
struct ContactEditor: View {
@zentrope
zentrope / ContentView.swift
Created October 21, 2021 19:35
Scroll Text in Content View
//
// ContentView.swift
// TestApp2
//
import SwiftUI
struct ContentView: View {
let author = "Moderator"
let title = "Daily Tech Support Thread"
@zentrope
zentrope / FetchController.swift
Created December 30, 2020 04:22
Fetch controller
func usersFetchController() -> NSFetchedResultsController<FKUser> {
let fetcher: NSFetchRequest = FKUser.fetchRequest()
fetcher.sortDescriptors = [ NSSortDescriptor(key: "id", ascending: false) ]
return NSFetchedResultsController(fetchRequest: fetcher, managedObjectContext: viewContext, sectionNameKeyPath: nil, cacheName: nil)
}
//
// UserData.swift
//
import Cocoa
import Combine
import ForumsKit
class UserData: NSObject, ObservableObject, NSFetchedResultsControllerDelegate {
@zentrope
zentrope / register.rkt
Created November 26, 2020 18:56
Incomplete token registry service in Racket Lang
#lang racket
(require db)
(require web-server/servlet)
(require web-server/servlet-env)
(require web-server/managers/none)
(define auth-token "3d99fd86-f62b-4583-a14c-e1151b093569")
(define db-name "register.sqlite")