Skip to content

Instantly share code, notes, and snippets.


Becca Royal-Gordon beccadax

View GitHub Profile

Introduce cross-import overlays to factor out cross-cutting APIs

  • Proposal: SE-NNNN
  • Authors: Becca Royal-Gordon, Varun Gandhi
  • Review Manager: TBD
  • Implementation: In master behind -Xfrontend -enable-cross-import-overlays
  • Status: Prototyped behind a feature flag


View WithUninitialized.swift
/// Passes a pointer to an uninitialized instance of `type` to `body`.
/// If `body` returns `true`, indicating that the memory has now been
/// initialized, returns the instance; otherwise returns `nil`.
@usableFromInline func withUninitialized<T>(
_ type: T.Type, do body: (UnsafeMutablePointer<T>) -> Bool
) -> T? {
let ptr = UnsafeMutablePointer<T>.allocate(capacity: 1)
defer { ptr.deallocate() }
guard body(ptr) else {
beccadax / ExpressibleByAppendingStringInterpolation.swift
Created Mar 16, 2019
A not-quite-functional way to simplify string interpolation conformances.
View ExpressibleByAppendingStringInterpolation.swift
struct _AppendingStringInterpolation<Result: ExpressibleByStringInterpolation> {
var result: Result
protocol ExpressibleByAppendingStringInterpolation: ExpressibleByStringInterpolation where StringInterpolation == _AppendingStringInterpolation<Self> {
init(stringLiteral: String)
mutating func append(_ value: Self)
extension ExpressibleByAppendingStringInterpolation where StringInterpolation == _AppendingStringInterpolation<Self> {
beccadax / UserDefaults+Codable.swift
Last active Jun 29, 2021
Encode Codable instances into UserDefaults. Use only with small instances.
View UserDefaults+Codable.swift
// UserDefaults+Codable.swift
// Converter UltraLight
// Created by Brent Royal-Gordon on 8/31/17.
// Copyright © 2017 Architechies. All rights reserved.
// MIT-licensed, go nuts with it.
import Foundation
beccadax / UICollectionViewLayout+indexPaths.swift
Created Jul 26, 2017
Collection for iterating through index paths in a collection view. Could be generalized.
View UICollectionViewLayout+indexPaths.swift
// UICollectionViewLayout+indexPaths.swift
// Converter Calc
// Created by Brent Royal-Gordon on 7/26/17.
// Copyright © 2017 Architechies. All rights reserved.
import UIKit
beccadax / Example.swift
Last active Jul 8, 2017
Explicit conversion operator for Swift.
View Example.swift
import Foundation
import ExplicitlyConvertible
let i8: Int8 = 8
let i64: Int64 = 64
i64 + ^i8 // => 72
struct Person {
var name: String
beccadax / Tuple.swift
Last active Jun 29, 2021
Exploring user-space tuple designs in the quest for variadic generics.
View Tuple.swift
// First, let's test out the basic design. This is basically just an
// HList.
// This recurses to the right because that makes subscripting simpler,
// at the cost of making appending impossible to generalize.
public protocol TupleProtocol: RandomAccessCollection
where Index == Int, IndexDistance == Int, Element == Any
associatedtype First
associatedtype Rest //: TupleProtocol
beccadax / JSONFeed.swift
Last active Jun 18, 2020
JSON Feed parser in Swift 4—now updated for Xcode 9 Beta 1. Uses the new Codable protocol and JSONDecoder class.
View JSONFeed.swift
import Foundation
let feedURL = URL(string: "")!
// MARK: Basic models
// We do not model the `userComment` field because it is not supposed to be used by
// machines. We do not model extensions because they should be ignored unless
// supported anyway.
struct Feed {