Skip to content

Instantly share code, notes, and snippets.

View zwaldowski's full-sized avatar

Zachary Waldowski zwaldowski

View GitHub Profile
/// Captures a Cocoa object as a parameter to a `@Sendable` function or closure.
@propertyWrapper
public struct Copy<Wrapped>: @unchecked Sendable where Wrapped: NSCopying {
// from: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md?plain=1#L568>
public let wrappedValue: Wrapped
public init(wrappedValue: Wrapped) {
self.wrappedValue = wrappedValue.copy() as! Wrapped // swiftlint:disable:this force_cast
}
}
@resultBuilder
struct ArrayBuilder<Element> {
static func buildExpression(_ expression: Element) -> [Element] {
[ expression ]
}
static func buildBlock(_ elements: [Element]...) -> [Element] {
elements.flatMap { $0 }
}

Hello, world!

Warning Warning

Info Info

@zwaldowski
zwaldowski / AtGlobalVisitor.swift
Last active April 28, 2022 17:38
SwiftSyntax: Scanning for property wrappers
import Foundation
import SwiftSyntax
class AtGlobalVisitor: SyntaxVisitor {
struct Result {
let name: String
let type: String
let location: SourceRange
let url: URL
@zwaldowski
zwaldowski / NSObject+Blocks.h
Created May 4, 2011 12:08
Perform blocks with delays and cancellation
//
// NSObject+Blocks.h
// Filemator
//
// Created by Zachary Waldowski on 4/12/11.
// Copyright 2011 Dizzy Technology. All rights reserved.
//
@interface NSObject (Blocks)
// swift-tools-version: 5.5
// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.
import PackageDescription
import AppleProductTypes
let package = Package(

Repackaging a Fat Static Library as an xcframework

Consider this directory tree from a vendor:

OwningTheLibs/
  OwningTheLibs.a
  include/
    OwningTheLibs/
      OwningTheLibs.h
@zwaldowski
zwaldowski / AssumeEqualUntilModified.swift
Created August 15, 2021 21:03
Property wrapper - Assume equal until modified; use `UIConfigurationColorTransformer` in custom structs
/// Customizes the behavior of automatically-generated `Equatable` and `Hashable` conformances.
@propertyWrapper
public struct AssumeEqualUntilModified<Wrapped> {
var modificationCount = 0
public var wrappedValue: Wrapped {
didSet {
modificationCount += 1
}
@zwaldowski
zwaldowski / Solarized.crtheme
Created January 15, 2012 18:05
Solarized Dark for CodeRunner
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundColor</key>
<string>0d2733</string>
<key>CharColor</key>
<string>cc256f</string>
<key>ClassColor</key>
<string>c1371f</string>
#!/usr/bin/env xcrun swift
import Foundation
import ApplicationServices
func sendEventToSystemProcess(eventToSend: AEEventID) throws {
let target = NSAppleEventDescriptor(bundleIdentifier: "com.apple.loginwindow")
let event = NSAppleEventDescriptor(eventClass: numericCast(kCoreEventClass), eventID: eventToSend, targetDescriptor: target, returnID: numericCast(kAutoGenerateReturnID), transactionID: numericCast(kAnyTransactionID))
try event.sendEventWithOptions([.NoReply, .NeverInteract, .DontRecord], timeout: 2.0)
}