Skip to content

Instantly share code, notes, and snippets.

View beccadax's full-sized avatar
🏝️
Vacationing

Becca Royal-Gordon beccadax

🏝️
Vacationing
View GitHub Profile
@beccadax
beccadax / Example.swift
Last active December 30, 2025 18:15
Elegant handling of localizable strings in Swift. Note: This code is in Swift 2 and would need updates to be used in modern Swift.
let color = "blue"
let num = 42
localized("Colorless green ideas sleep furiously.")
localized("Colorless \(color) ideas sleep furiously.")
localized("\(num.formatted("%05d")) colorless green ideas sleep furiously.")

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

@beccadax
beccadax / gist:3977323
Created October 29, 2012 23:32
Basic use of ANEntitySet and ANEntity
// Note that I have never run this code; it may have bugs or even be syntactically invalid.
- (NSAttributedString*)attributedTextForPost:(ANPost*)post {
NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:post.text];
for(ANEntity * entity in post.entities.all) {
[attributedText setAttributes:@{
NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
@"entity": entity
@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 / 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
@beccadax
beccadax / trash.swift
Last active March 5, 2021 01:27
A trash command as a Swift script.
#!/usr/bin/xcrun swift
import Dispatch
import Cocoa
dispatch_async(dispatch_get_main_queue()) {
let URLsToRecycle = Array(dropFirst(Process.arguments)).map { NSURL(fileURLWithPath: $0) }
NSWorkspace.sharedWorkspace().recycleURLs(URLsToRecycle) { dict, error in
let recycledURLs = Array(dict.keys) as [NSURL]
@beccadax
beccadax / Example.swift
Created July 26, 2016 12:28
Alternate design for RelativeRange
let array = Array(1...10)
array[.startIndex ..< 3]
array[.startIndex + 2 ..< .endIndex - 1]
@beccadax
beccadax / xmlbuilder.swift
Created December 1, 2014 23:22
Generating XML from Swift.
// Playground - noun: a place where people can play
import Foundation
protocol XMLChild {
var XMLNode: NSXMLNode { get }
}
extension String: XMLChild {
var XMLNode: NSXMLNode {
@beccadax
beccadax / LocalizableString-new-interpolation.swift
Created March 11, 2017 01:44
An implementation of a LocalizableString type in the Swift new-interpolation branch: https://github.com/brentdax/swift/tree/new-interpolation
import Foundation
public protocol LocalizableArgument {
var localizableFormat: String { get }
var localizableFormatArguments: [CVarArg] { get }
}
extension LocalizableArgument where Self: CVarArg {
public var localizableFormatArguments: [CVarArg] {
return [self]