[swift-users] Protocols, `mutating` and Value vs Reference Types.

Dave Abrahams dabrahams at apple.com
Fri Apr 29 19:28:23 CDT 2016


on Fri Apr 29 2016, Hooman Mehr <swift-users-AT-swift.org> wrote:

> Hi,
>
> I am designing APIs that need to support both reference (class/object) and value
> types. I am running into restrictions of `mutating` keyword in my protocols and
> this is causing a lot of duplication of code. In order to understand what I mean
> please take a look at this gist. 
>
> As you see, I have pairs of almost identical declarations: KeyValueStore vs
> KeyValueStoreObject, and AnyDictionaryStore vs AnyDictionaryStoreObject. This
> keeps rapidly growing as I am designing my APIs. Is there any sane way around
> this?

protocol KeyValueStoreObject : class, KeyValueStore {}
protocol AnyDictionaryStoreObject : class, AnyDictionaryStore {}

would probably work for you.

HTH,

-- 
Dave



More information about the swift-users mailing list