Skip to content

Instantly share code, notes, and snippets.

Avatar

Brent Simmons brentsimmons

View GitHub Profile
View protocolequatable.swift
//: Playground - noun: a place where people can play
import Cocoa
protocol Account: Hashable {
var accountID: String {get}
var hashValue: Int {get}
}
@brentsimmons
brentsimmons / PointerEquality.swift
Last active Aug 29, 2015
Protocols and pointer equality
View PointerEquality.swift
//: Playground - noun: a place where people can play
import Cocoa
// Solution: if I use "class" instead of "AnyObject", then it’s a pure Swift solution:
// http://inessential.com/2015/07/23/swift_diary_3_arrays_protocols_and_p
// https://twitter.com/_mattrubin/status/624266521896992768
// Or… AnyObject may be marked @objc, but it is in fact a native Swift feature:
// https://twitter.com/jckarter/status/624270700614942721
@brentsimmons
brentsimmons / gist:2080595ac8a6f41711af
Last active Aug 29, 2015
Swift init from unknown class
View gist:2080595ac8a6f41711af
import Cocoa
protocol Thing {
var x: String {get}
init(s: String)
}
class Foo: Thing {
let x: String
@brentsimmons
brentsimmons / gist:5ccd357f0fa1486bdc3f
Created Jul 20, 2015
Class is unknown until runtime
View gist:5ccd357f0fa1486bdc3f
// How do you do this in Swift?
- (Class)classToUse {
return [Foo class]; // assume it's something else sometimes
}
- (id)generateThingForString:(NSString *)s {
Class thingClass = [self classToUse];
return [[thingClass alloc] initWithString:s];
}
@brentsimmons
brentsimmons / headerview.m
Created Apr 26, 2014
UITableView header issues
View headerview.m
#pragma mark - Class Methods
+ (BOOL)requiresConstraintBasedLayout {
return YES;
}
#pragma mark - Init
- (id)initWithFrame:(CGRect)frame {
View metaweblog.rb
#!/usr/bin/env ruby -wKU
# Comments added 6 March 2014.
# Implementation of the MetaWeblog API for my personal Ruby static blog generator.
# This is not even nearly idiomatic Ruby. There are all kinds of issues.
# (What's with the method interiors all being mushed-up together?)
# But -- it's also worked flawlessly for five years without my having to edit it.
# It won't work for anyone else as-is — but if it helps anyone
# to do a MetaWeblog API implementation, then cool.
View VSTagAuthoritySQL.m
//
// VSTagAuthoritySQL.m
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
#import <libkern/OSAtomic.h>
#import "VSTagAuthoritySQL.h"
View VSTagAuthoritySQL.h
//
// VSTagAuthoritySQL.h
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
View VSTagAuthority.m
//
// VSTagAuthority.m
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
#import "VSTagAuthority.h"
#import "VSTag.h"
View VSTagAuthority.h
//
// VSTagAuthority.h
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
/*
You can’t perform that action at this time.