This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MultiColumnText: View { | |
private let storage: NSTextStorage | |
private let layoutManager: NSLayoutManager = .init() | |
private let containers: [NSTextContainer] | |
init(text: NSAttributedString, columns: Int) { | |
storage = .init(attributedString: text) | |
storage.addLayoutManager(layoutManager) | |
containers = (0..<columns).map {_ in .init()} | |
containers.forEach { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
import CoreBluetooth | |
import AppKit | |
class AppDelegate: NSResponder, CBCentralManagerDelegate, NSTouchBarDelegate, NSApplicationDelegate { | |
let manager: CBCentralManager | |
var advertises: [Advertise] = [] | |
override init() { | |
manager = CBCentralManager(delegate: nil, queue: DispatchQueue.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RealityKit | |
extension ShapeResource { | |
/// generate a box with its surfaces facing inward. | |
/// NOTE: size 30 works with interactions, 50 does not work with interactions | |
static func generateInwardBox(size: Float) async throws -> ShapeResource { | |
// An array of vertex positions containing discrete points on the mesh. | |
let meshPositions: [SIMD3<Float>] = [ | |
.init(-1, -1, -1), // 0 LBF | |
.init(+1, -1, -1), // 1 RBF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// prerequisites in Info.plist: NSUserActivityTypes contains type, UIApplicationSceneManifest/UIApplicationSupportsMultipleScenes = YES | |
// accepts NSUserActivity.targetContentIdentifier = type | |
// see also: https://developer.apple.com/documentation/swiftui/scene/handlesexternalevents(matching:) | |
struct UserActivityWindowGroup<Content: View, Payload: Codable>: Scene { | |
var type: String | |
@ViewBuilder var content: (Payload) -> Content | |
init(type: String, payloadType: Payload.Type, @ViewBuilder content: @escaping (Payload) -> Content) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import CoreGraphics | |
import Vision | |
struct TargetWindow { | |
let id: CGWindowID | |
let bounds: CGRect | |
init?(appName: String, windowTitle: String) { | |
guard let windows = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID) as? [[String: Any]] else { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
if [[ -z $BOGO_ARM64_TO_SIM ]]; then | |
echo "❌ requires BOGO_ARM64_TO_SIM: set an executable binary path built from https://github.com/bogo/arm64-to-sim" | |
exit 1; | |
fi | |
set -eu | |
# set -x # debug log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension AVCaptureDevice { | |
class func swizzle() { | |
[(#selector(AVCaptureDevice.defaultDevice(withMediaType:)), #selector(AVCaptureDevice.mockDefaultDevice(withMediaType:)))].forEach { | |
let original = class_getClassMethod(self, $0) | |
let mock = class_getClassMethod(self, $1) | |
method_exchangeImplementations(original, mock) | |
} | |
[(#selector(AVCaptureDevice.hasMediaType(_:)), #selector(AVCaptureDevice.mockHasMediaType(_:))), | |
(#selector(AVCaptureDevice.supportsAVCaptureSessionPreset(_:)), #selector(AVCaptureDevice.mockSupportsAVCaptureSessionPreset)), | |
(#selector(AVCaptureDevice.isTorchModeSupported(_:)), #selector(AVCaptureDevice.mockIsTorchModeSupported)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let audioOutput: AVCaptureAudioPreviewOutput = { | |
let audioOutput = AVCaptureAudioPreviewOutput() | |
audioOutput.volume = UserDefaults.standard.volume | |
struct Device { | |
var name: String? | |
var uid: String? | |
} | |
var devicesProperty = AudioObjectPropertyAddress(mSelector: kAudioHardwarePropertyDevices, mScope: kAudioDevicePropertyScopeOutput, mElement: kAudioObjectPropertyElementWildcard) | |
var devicesSize: UInt32 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import CoreMediaIO | |
import AVFoundation | |
class ViewController: NSViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
var prop = CMIOObjectPropertyAddress( | |
mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate: NSResponder, NSTouchBarDelegate, NSApplicationDelegate { | |
@available(OSX 10.12.2, *) | |
lazy var touchbar: NSTouchBar = { | |
let tb = NSTouchBar() | |
tb.delegate = self | |
tb.defaultItemIdentifiers = [NSTouchBarItemIdentifier(rawValue: "test")] | |
return tb | |
}() |
NewerOlder