Skip to content

Instantly share code, notes, and snippets.

View beccadax's full-sized avatar

Becca Royal-Gordon beccadax

View GitHub Profile
@beccadax
beccadax / with.md
Last active May 27, 2016 19:04 — forked from erica/with.md

Introducing with to the Standard Library

Introduction

This proposal introduces a with function to the standard library. This function

@beccadax
beccadax / CoreDatalike.swift
Last active May 25, 2016 04:25
A sketch of something rather like Core Data, written in pure Swift with property behaviors and a couple other likely future features.
// Here's what usage looks like:
class Person: ManagedObject {
// Note: Although the proposal shows `var [foo]`, current thinking is
// actually that we'll use `@foo var`.
@persistent var name: String
@persistent var birthDate: Date
@persistent var socialSecurityNumber: String?
@persistent var children: Set<Person>
@beccadax
beccadax / codes2swift.swift
Last active May 5, 2016 20:20
Some code-generating code, converted to use proposed string features
#!/Library/Developer/Toolchains/swift-LOCAL-2016-05-04-a.xctoolchain/usr/bin/swift
//
// codes2swift.swift
// WebResponderCore
//
// Created by Brent Royal-Gordon on 6/20/15.
// Copyright © 2015 Groundbreaking Software. All rights reserved.
//
import Foundation
@beccadax
beccadax / quotetest.swift
Last active May 3, 2016 00:30
Tests for new quoting features.
#!/Library/Developer/Toolchains/swift-LOCAL-2016-05-02-a.xctoolchain/usr/bin/swift
// Change the line above if your prototype Swift interpreter is installed somewhere else.
// The easiest way to run this on El Capitan is:
// $ perl /usr/bin/prove5.18 quotetest.swift --verbose
/// Test output generator. Skip down to the comment that says "BEGIN TESTS" for the good stuff.
class Plan {
enum Verbosity {
case Always, Unexpected, Never
@beccadax
beccadax / Multiline string literals.md
Last active March 9, 2017 01:03
Multiline string literals proposal
@beccadax
beccadax / Example.swift
Last active April 7, 2016 11:19
Suggested replacement for C-style for.
// Sequence of 1, 2, 4 ... 64
induce(from: 1, to: 128, by: { $0 * 2 })
induce(from: 1, to: 128, by: { $0 *= 2 })
// Sequence of 1, 2, 4 ... 128
induce(from: 1, through: 128, by: { $0 * 2 })
induce(from: 1, through: 128, by: { $0 *= 2 })
// Sequence of 1, 2, 4 ... with arbitrary, calculated bound
import Darwin
@beccadax
beccadax / DateStriding2.swift
Last active March 30, 2016 05:47
Second design for striding over dates
import Foundation
extension NSCalendar {
public enum Interval {
case zero
case other(n: Int, calendar: NSCalendar, unit: NSCalendarUnit, options: NSCalendarOptions)
init(n: Int, calendar: NSCalendar, unit: NSCalendarUnit, options: NSCalendarOptions) {
if n == 0 {
self = .zero
@beccadax
beccadax / DateStriding.swift
Created March 30, 2016 04:28
Experiment with striding over NSDates using a view
import Foundation
extension NSDate {
func unitView(unit: NSCalendarUnit, for calendar: NSCalendar = NSCalendar.currentCalendar(), options: NSCalendarOptions = [.MatchNextTimePreservingSmallerUnits]) -> UnitView {
return UnitView(calendar: calendar, date: self, unit: unit, options: options)
}
struct UnitView: Strideable, CustomStringConvertible {
let calendar: NSCalendar
let date: NSDate
@beccadax
beccadax / InfiniteGeneratorType.swift
Created March 17, 2016 21:51
Protocol for a generator that never stops returning values
protocol InfiniteGeneratorType: GeneratorType {
mutating func next() -> Element
}
extension InfiniteGeneratorType {
mutating func next() -> Self.Element? {
return next() as Element
}
}
newCacheNodeForManagedObject -> NSAtomicStoreCacheNode
cacheNodes -> Set
cacheNodeForObjectID -> NSAtomicStoreCacheNode?
objectIDForEntity -> NSManagedObjectID
newReferenceObjectForManagedObject -> AnyObject
referenceObjectForObjectID -> AnyObject
valueForKey -> AnyObject?
entityForName -> NSEntityDescription?
insertNewObjectForEntityForName -> NSManagedObject
relationshipsWithDestinationEntity -> [NSRelationshipDescription]