From 028663b0bd165949821072c196949db47256a5d4 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Thu, 21 Apr 2016 19:37:16 +0200 Subject: [PATCH] Automatically convert CustomStringConvertible key types to strings If a custom value is used as a dictionary key and it conforms to CustomStringConvertible, automatically use the `description` as the wrapped key. --- Wrap.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Wrap.swift b/Wrap.swift index aea4b90..e296bb9 100644 --- a/Wrap.swift +++ b/Wrap.swift @@ -339,6 +339,8 @@ private extension Wrapper { wrappedKey = stringKey } else if let wrappableKey = key as? WrappableKey { wrappedKey = wrappableKey.toWrappedKey() + } else if let stringConvertible = key as? CustomStringConvertible { + wrappedKey = stringConvertible.description } else { wrappedKey = nil }