Skip to content

Instantly share code, notes, and snippets.

@alexanderedge
alexanderedge / CustomPicker.swift
Created March 28, 2021 16:10
Custom picker using style via environment
import SwiftUI
struct ContentView: View {
@State private var selection: Int = 0
var body: some View {
CustomPicker(selection: $selection) {
// ForEach(0..<10) {
// Text("\($0)")
// }
@alexanderedge
alexanderedge / StaticGestureRecognisers.swift
Last active December 8, 2015 10:09
Statically-typed functions for simple gesture recognisers
protocol Tappable : AnyObject {
func handleTap(gr : UITapGestureRecognizer)
}
extension UITapGestureRecognizer {
convenience init(target : Tappable) {
self.init(target: target, action: "handleTap:")
}
}
@alexanderedge
alexanderedge / Maths.swift
Last active August 29, 2015 14:26
Swift protocol extensions
protocol Raisable {
func raise(exponent : Self) -> Self
}
extension Raisable where Self : SignedNumberType {
func raise(exponent : Self) {
return pow(self, exponent)
}
}
### Keybase proof
I hereby claim:
* I am alexanderedge on github.
* I am alexanderedge (https://keybase.io/alexanderedge) on keybase.
* I have a public key whose fingerprint is CD91 F7A8 42E6 9523 9D81 8BAD 1235 714B ECC8 4438
To claim this, I am signing this object:
@alexanderedge
alexanderedge / Vagrantfile
Created September 16, 2013 09:34
Ruby 2.0 + Rails 4.0 Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
@alexanderedge
alexanderedge / AGEColor
Last active October 17, 2016 18:47
Macros for generating UIColor instances only once, increasing application performance.
//
// AGEColor.h
//
// Copyright (c) 2013 Alexander Edge (http://www.alexedge.co.uk)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@alexanderedge
alexanderedge / gist:5005981
Last active December 14, 2015 01:28
Adding this to any class conforming to NSObject protocol will print out the instance's properties in a friendly format when passed to `+ (NSString *)stringWithFormat:`
#import <objc/runtime.h>
- (NSString *)description{
NSMutableString *objectDescription = [NSMutableString stringWithFormat:@"<%@: %p ",NSStringFromClass([self class]),self];
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList([self class], &outCount);