Skip to content

Instantly share code, notes, and snippets.

View BrandonShega's full-sized avatar

Brandon Shega BrandonShega

View GitHub Profile
@BrandonShega
BrandonShega / Playground.swift
Last active June 22, 2017 13:52
Transition with completion
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
import PlaygroundSupport
extension UINavigationController {
func popViewController(completion: @escaping () -> ()) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
@BrandonShega
BrandonShega / Playground.swift
Last active March 27, 2017 20:03
Queue with two stacks
var queue = Queue<String>()
queue.enqueue("Hello")
queue.enqueue("World")
queue.dequeue() // "Hello"
queue.dequeue() // "World"
queue.dequeue() // nil
@BrandonShega
BrandonShega / enum.swift
Last active March 23, 2017 18:22
Iteratable Enum
protocol Iteratable {}
extension RawRepresentable where Self: RawRepresentable {
static func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> {
var i = 0
return AnyIterator {
let next = withUnsafePointer(to: &i) {
$0.withMemoryRebound(to: T.self, capacity: 1) { $0.pointee }
}
if next.hashValue != i { return nil }
i += 1

Keybase proof

I hereby claim:

  • I am brandonshega on github.
  • I am bshega (https://keybase.io/bshega) on keybase.
  • I have a public key ASA9VwW7yXulOo0DGhcJVrb4h5wUC--U1wzHrPuYzmQG6Qo

To claim this, I am signing this object:

@BrandonShega
BrandonShega / playground.swift
Last active May 26, 2022 09:46
Table View Section Index List
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
let allStates = ["Alaska",
"Alabama",
"Arkansas",
"American Samoa",
@BrandonShega
BrandonShega / playground.swift
Created March 8, 2017 14:15
Delegate Example
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
protocol MyDelegate: class {
func didTapButton()
}
@BrandonShega
BrandonShega / challenge.swift
Last active March 6, 2017 18:07
Ease the StockBroker
func balanceStatements(_ list: String) -> String {
var totalBuy = 0
var totalSell = 0
var malformedCount = 0
var malformedOrders = [String]()
let pattern = "\\w+ \\w+ \\d+\\.\\d+ \\w+"
let orders = list.components(separatedBy: ",").filter { !$0.isEmpty }
for order in orders {
@BrandonShega
BrandonShega / DelegatePlayground.swift
Last active January 25, 2017 15:24
Delegate Demonstration
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
var str = "Hello, playground"
protocol EditViewControllerDelegate: class {
func didFinishEditing()
}
@BrandonShega
BrandonShega / playground.swift
Created December 14, 2016 21:10
Playground TDD
import XCTest
class PlaygroundTestObserver: NSObject, XCTestObservation {
@objc func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
print("Test failed on line \(lineNumber): \(testCase.name), \(description)")
}
}
struct TestRunner {
func runTests(testClass: AnyClass) {
@BrandonShega
BrandonShega / modal.swift
Created November 30, 2016 14:23
Modal View Controller with constraints
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
var str = "Hello, playground"
class MainViewController: UIViewController {
let button: UIButton = {