Skip to content

Instantly share code, notes, and snippets.

View chrisjenkins's full-sized avatar

Chris Jenkins chrisjenkins

View GitHub Profile
@nicklockwood
nicklockwood / OSKit.swift
Created January 28, 2023 11:32
A lightweight approach to writing cross-platform code in SwiftUI without a lot of conditional compilation blocks
import SwiftUI
enum OSDocumentError: Error {
case unknownFileFormat
}
#if canImport(UIKit)
import UIKit
@chipjarred
chipjarred / SwiftUIKeyDetection.swift
Last active June 2, 2023 18:52
Detecting keyboard state in SwiftUI
import SwiftUI
extension CGKeyCode
{
// Define whatever key codes you want to detect here
static let kVK_Space: CGKeyCode = 0x31
var isPressed: Bool {
CGEventSource.keyState(.combinedSessionState, key: self)
}