Skip to content

Instantly share code, notes, and snippets.

View abey's full-sized avatar

Abey Thomas abey

View GitHub Profile
@abey
abey / XCTest+loadJSON.swift
Last active August 14, 2020 17:42
Load JSON file
import XCTest
extension XCTest {
func loadFromJSON<T: Codable>(jsonFileName filename: String) -> T? {
guard let url = Bundle(for: type(of: self)).url(forResource: filename, withExtension: "json") else {
XCTFail("Unable to read \(filename) from stub")
return nil
}
do {
@abey
abey / Array+Permutations.swift
Created March 29, 2020 22:12
Generate Permutations of a Swift Array
// abey.dev
import Foundation
extension Array {
func decompose() -> (Iterator.Element, [Iterator.Element])? {
guard let x = first else { return nil }
return (x, Array(self[1..<count]))
}
}