Skip to content

Instantly share code, notes, and snippets.

Avatar

Rob Napier rnapier

View GitHub Profile
@rnapier
rnapier / error-propagation.swift
Last active Apr 27, 2017 — forked from nicklockwood/error-propagation.swift
Typed error use-case example
View error-propagation.swift
// 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
View closure.md

Enhancing closure argument flexibility

Introduction

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

View dispatch-sync-safe.swift
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