Last active
February 18, 2019 12:43
-
-
Save CognitiveDisson/7f8e9e29c2ab458820a83d13c1414231 to your computer and use it in GitHub Desktop.
swift concurrent dictionary enumeration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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