Skip to content

Instantly share code, notes, and snippets.

Deprecate @UIApplicationMain and @NSApplicationMain


@UIApplicationMain and @NSApplicationMain used to be the standard way for iOS and macOS apps respectively to declare a synthesized platform-specific entrypoint for an app. These functions have since been obsoleted by SE-0281 and the @main attribute, and now represent a confusing bit of duplication in the language. This proposal seeks to deprecate these alternative entrypoint attributes in favor of @main in Swift 5.8, and makes their use in Swift 6 a hard error.

CodaFi / IP.swift
Last active June 3, 2023 05:32
An async sequence of kevents
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#error("unsupported platform")
/// Core utilities for interacting with IP-based abstractions.
public struct IP {


Swift’s type system supports a number of different ways of taking a function or type and abstracting it. Usually, this is done by adding a generic parameter and an associated set of constraints. Similarly, a function that takes a particular type of argument can be abstracted to any number of those arguments by making it variadic with triple-dot (...) syntax. Today, both of these features are permitted separately: you can define a generic function that takes a variable number of arguments, such as

func debugPrint<T>(_ items: T...) 
  where T: CustomDebugStringConvertible
  for (item: T) in items {
class AsyncOperation: Operation {
private(set) var taskHandle: Task.Handle<Void, Error>?
fileprivate enum State: Equatable {
case ready
case executing
case finished
fileprivate var state: State = .ready {
# NOTE: You need sccache first - but if you already have it, this'll void your cache.
env SCCACHE_RECACHE=1 caffeinate ./swift/utils/build-script -R --cmake-cxx-launcher (which sccache) --cmake-c-launcher (which sccache) --skip-build-benchmark
./utils/build-script -r --foundation --swiftpm --llbuild --libdispatch --install-swift --install-swiftpm --install-llbuild --install-foundation --install-libdispatch --xctest --install-xctest --install-swift --install-swiftpm --install-llbuild --install-foundation --install-libdispatch --xctest --install-xctest --test --skip-test-swift --skip-test-foundation --indexstore-db '--llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-resource-headers;compiler-rt;clangd;lld'
./utils/build-script -r --foundation --swiftpm --llbuild --libdispatch --install-swift --install-swiftpm --install-llbuild --install-foundation --install-libdispatch --xctest --install-xctest --install-swift --install-swiftpm --install-llbuild --install-foundation --install-libdispatch --xctest --install-xctest --test --skip-test-swift --skip-test-foundation --indexstore-db '--llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-resource-headers;compiler-rt;clangd;lld' --skip-test-libdispatch --ski
CodaFi / MBE.swift
Created July 8, 2018 06:33
Macro-by-Example: Deriving Syntactic Transformations from their Specifications, Re-Typeset
//: Foreword
//: This playground is the culmination of a week of digging around
//: for the oldest papers I could find about (Lisp) macros and their evolution.
//: I found this paper particularly enlightening as it is the place where Scheme
//: and Rust-style "Macro-by-Example" macros first came into their own. In
//: addition, this paper discusses the implementation challenges faced by
//: previous macro systems and Kohlbecker's first go at MBEs.
//: I have re-typeset this paper because [the one hosted by IU](
//: Playground - noun: a place where people can play
//: Roots of Unity Often Lie
indirect enum BTree {
case empty
case branch(BTree, BTree)
func encode(_ t: (BTree, BTree, BTree, BTree, BTree, BTree, BTree)) -> BTree {
switch t {
CodaFi / Nub.agda
Created April 20, 2018 23:33
Agda wrote nub for me (with some prodding)
module Untitled where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Char hiding (_≟_)
open import Data.Bool hiding (_≟_)
open import Data.List
open import Data.Unit hiding (_≟_)
open import Data.Empty
open import Relation.Nullary
CodaFi / turing-fake.swift
Last active November 25, 2021 00:50 — forked from garrigue/
struct State0 {}; struct State1 {}; struct FinalState {} /*States*/
struct Symbol {}; struct Blank {} /*Symbols*/
struct Left {}; struct Right {} /*Directions*/
struct EndOfTape {} /*End of Tape*/
struct Transition<StartState, StartHead, EndState, EndHead, Direction> {
static func transitionOne() -> Transition<State0, Blank, State1, Symbol, Left> { fatalError() }
static func transitionTwo() -> Transition<State1, Blank, State0, Symbol, Right> { fatalError() }
static func transitionThree<State>() -> Transition<State, Symbol, FinalState, Symbol, Left> { fatalError() }