Skip to content

Instantly share code, notes, and snippets.

View rnapier's full-sized avatar

Rob Napier rnapier

View GitHub Profile
func dispatch_sync<R> (queue: dispatch_queue_t, block: Void -> R ) -> R {
var result: R!
dispatch_sync(queue) {
result = block()
}
return result
}
func result() -> String {
return
@rnapier
rnapier / closure.md
Last active May 14, 2016 16:00 — forked from erica/closure.md

Enhancing closure argument flexibility

Introduction

This proposal loosens closure requirements to provide developer flexibility. It removes the _ in requirement

@rnapier
rnapier / error-propagation.swift
Last active April 27, 2017 14:01 — forked from nicklockwood/error-propagation.swift
Typed error use-case example
// I know you meant it to be exaggerated, but I still think this is the better approach in practice:
enum ClassError: Error {
case propertyNotFound(name: String)
case typeMismatch(propertyName: String)
}
class Foo {
var properties: [(String, Any)] = []
private func validateValue(_ value: Any, for property: String) throws { // Note that I pass the name just for the error; that's ok IMO