Skip to content

Instantly share code, notes, and snippets.

Rob Napier rnapier

Block or report user

Report or block rnapier

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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

Enhancing closure argument flexibility


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 {
You can’t perform that action at this time.