Skip to content

Instantly share code, notes, and snippets.

@htinlinn
htinlinn / DecodableRoot.swift
Last active June 3, 2023 21:10
Decode JSON at root level based on a key
extension JSONDecoder {
func decode<T: Decodable>(_ type: T.Type, from data: Data, keyedBy key: String?) throws -> T {
if let key = key {
// Pass the top level key to the decoder.
userInfo[.jsonDecoderRootKeyName] = key
let root = try decode(DecodableRoot<T>.self, from: data)
return root.value
} else {
@htinlinn
htinlinn / format-objc-hook
Created September 18, 2015 19:11
Custom pre-commit hook for space commander
#!/usr/bin/env bash
# ~/.git_template.local/hooks/pre-commit
# format-objc-hook
# pre-commit hook to check if any unformatted Objective-C files would be committed. Fails the check if so, and provides instructions.
#
# Copyright 2015 Square, Inc
IFS=$'\n'
export CDPATH=""
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )