Skip to content

Instantly share code, notes, and snippets.

@CognitiveDisson
Last active February 18, 2019 12:43
Show Gist options
  • Save CognitiveDisson/7f8e9e29c2ab458820a83d13c1414231 to your computer and use it in GitHub Desktop.
Save CognitiveDisson/7f8e9e29c2ab458820a83d13c1414231 to your computer and use it in GitHub Desktop.
swift concurrent dictionary enumeration
import Foundation
extension Dictionary {
func enumerateKeysAndObjects(
options opts: NSEnumerationOptions = [],
using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) throws -> Void) throws
{
var blockError: Error?
(self as NSDictionary).enumerateKeysAndObjects(options: opts) { (key, obj, stops) in
do {
try block(key, obj, stops)
} catch {
blockError = error
stops.pointee = true
}
}
if let error = blockError {
throw error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment