Skip to content

Instantly share code, notes, and snippets.

Avatar

Stuart Breckenridge stuartbreckenridge

View GitHub Profile
@stuartbreckenridge
stuartbreckenridge / GameCenterInteractor
Last active Sep 10, 2015
Game Center Authentication
View GameCenterInteractor
//
// GameCenterInteractor.swift
// GameKitInteraction
//
// Created by Stuart Breckenridge on 19/11/14.
// Copyright (c) 2014 Stuart Breckenridge. All rights reserved.
//
import UIKit
import GameCenter
@stuartbreckenridge
stuartbreckenridge / NumberGenerator
Created Jan 17, 2015
Number Generator for Lottery Games.
View NumberGenerator
class NumberGenerator
{
class func generateLottoNumbers(#count:Int,maxRange:UInt32, duplicatesAllowed:Bool = false) -> ([Int])
{
var i = 0
var uniqueSet = NSMutableSet(capacity: count)
var numberArray1 = [Int]()
do{
var genNumber = (Int(arc4random() % maxRange + 1))
@stuartbreckenridge
stuartbreckenridge / UIAlertControllerErrorDisplay
Created Nov 20, 2015
Remove boilerplate when displaying UIAlertControllers from a UIViewController
View UIAlertControllerErrorDisplay
protocol UIAlertControllerErrorDisplay
{
func showAlertControllerWithError(error:NSError)
}
extension UIViewController:UIAlertControllerErrorDisplay
{
func showAlertControllerWithError(error:NSError)
{
NSOperationQueue.mainQueue().addOperationWithBlock { () -> Void in
@stuartbreckenridge
stuartbreckenridge / SwiftGCD.swift
Created Feb 13, 2016
Swiftier GCD (via NSHipster)
View SwiftGCD.swift
protocol ExcutableQueue {
var queue: dispatch_queue_t { get }
}
extension ExcutableQueue {
func execute(closure: () -> Void) {
dispatch_async(queue, closure)
}
}
View gist:240e52af14ca50e2a4ce
protocol AmountConversions
{
// Convert Mls
func convertMlsToUKFLOz(mls:Int) -> NSNumber // mls * 0.035195
func convertMlsToUSFLOz(mls:Int) -> NSNumber // mls * 0.033814
// Convert UKFLOz
func convertUKFLOzToMls(ukfloz:Float) -> NSNumber // uk fl oz / 0.035195
func convertUKFLOzToUSFLOz(ukfloz:Float) -> NSNumber // uk fl oz * 0.96076
@stuartbreckenridge
stuartbreckenridge / SLComposable.swift
Last active May 25, 2016
SLComposable Protocol—Easy to use protocol for creation and presentation of SLComposeViewControllers
View SLComposable.swift
//
// SLComposable.swift
// SocialFrameworkRef
//
// Created by Stuart Breckenridge on 24/05/2016.
// Copyright © 2016 Stuart Breckenridge. All rights reserved.
//
import Foundation
import Social
@stuartbreckenridge
stuartbreckenridge / ConstantShortHand.swift
Last active May 28, 2016
Configuring a Constant Using Shorthand Argument Labels
View ConstantShortHand.swift
// See https://www.natashatherobot.com/swift-configuring-a-constant-using-shorthand-argument-names/ for more info.
public enum TaxiServiceType:CustomStringConvertible
{
case Uber
case BlackCab
public var description: String {
switch self {
case .BlackCab:
@stuartbreckenridge
stuartbreckenridge / INRConversions.swift
Created Jul 21, 2016
Currency Converter for the Indian Numbering System
View INRConversions.swift
class UnitIndianCurrency:Dimension {
static let rupees = UnitIndianCurrency(symbol: "rupees", converter: UnitConverterLinear(coefficient: 1.0))
static let hazar = UnitIndianCurrency(symbol: "hazar", converter: UnitConverterLinear(coefficient: 1000.0))
static let lahk = UnitIndianCurrency(symbol: "lahk", converter: UnitConverterLinear(coefficient: 100000.0))
static let crore = UnitIndianCurrency(symbol: "crore", converter: UnitConverterLinear(coefficient: 10000000.0))
static let arab = UnitIndianCurrency(symbol: "arab", converter: UnitConverterLinear(coefficient: 1000000000.0))
View keybase.md

Keybase proof

I hereby claim:

  • I am stuartbreckenridge on github.
  • I am sgb (https://keybase.io/sgb) on keybase.
  • I have a public key ASBRWJ1N53LHzhy1uzkmVvvq-ZuK-UJoiZ4ktkWZOe6xcwo

To claim this, I am signing this object:

@stuartbreckenridge
stuartbreckenridge / Collatz.playground
Created Aug 10, 2016
A Swift implementation of the Collatz Conjecture, with full playground markup.
View Collatz.playground
import UIKit
//: # The Collatz Conjecture
//: *This process will eventually reach the number 1, regardless of which positive integer is chosen initially. (See [Wikipedia](https://en.wikipedia.org/wiki/Collatz_conjecture).)*
//: \
//: Create an array to capture the sequence of numbers returned by the `collatz` function.
var sequence = [Int]()
//: The `collatz(start:Int, initial:Bool) -> [Int]` function takes an integer and will perform the following:
//:- if the integer (`n`) is 1, it will return an `[Int]` array.