Skip to content

Instantly share code, notes, and snippets.

View beccadax's full-sized avatar

Becca Royal-Gordon beccadax

View GitHub Profile

Objective-C implementations in Swift

  • Proposal: SE-NNNN
  • Authors: Becca Royal-Gordon
  • Review Manager: TBD
  • Status: Awaiting implementation (but only of resilience support)
  • Implementation: In main and release/6.0, behind the ObjCImplementation experimental feature flag
  • Upcoming Feature Flag: ObjCImplementation

Introduction

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

Introduction

/// 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
beccadax / ExpressibleByAppendingStringInterpolation.swift
Created March 16, 2019 03:37
A not-quite-functional way to simplify string interpolation conformances.
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
beccadax / raw.md
Last active July 2, 2018 20:07 — forked from erica/oldraw.md
@beccadax
beccadax / UserDefaults+Codable.swift
Last active June 29, 2021 12:52
Encode Codable instances into UserDefaults. Use only with small instances.
//
// 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
beccadax / UICollectionViewLayout+indexPaths.swift
Created July 26, 2017 22:32
Collection for iterating through index paths in a collection view. Could be generalized.
//
// UICollectionViewLayout+indexPaths.swift
// Converter Calc
//
// Created by Brent Royal-Gordon on 7/26/17.
// Copyright © 2017 Architechies. All rights reserved.
//
import UIKit
@beccadax
beccadax / Example.swift
Last active July 8, 2017 12:31
Explicit conversion operator for Swift.
import Foundation
import ExplicitlyConvertible
let i8: Int8 = 8
let i64: Int64 = 64
i64 + ^i8 // => 72
struct Person {
var name: String
@beccadax
beccadax / Tuple.swift
Last active June 29, 2021 12:51
Exploring user-space tuple designs in the quest for variadic generics.
// 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