Using ... as a concrete type conforming to protocol ... is not supported

Hi all,

I was trying to do something like below in Xcode 7.2.1-

public protocol KeyType : Hashable {
    
}

public protocol ValueType {
    
}

struct MyConcrete : MyProtocol {
    let values : [KeyType: ValueType]
}

extension Dictionary where Key: KeyType, Value: ValueType {
    
    public var theThing : MyProtocol {
        get {
            return MyConcrete(self)
        }
    }
}

The problem I get with the code above is -
Using ‘KeyType' as a concrete type conforming to protocol 'Hashable' is not supported

Alternatively, changing KeyType to be a concrete type (such as String) results in the error on the extension-
type 'Key' constrained to non-protocol type ‘String'

The ideal situation would use Conditional conformance so a [KeyType: ValueType] could itself conform to MyProtocol. This looks like it will come with Swift 3. Is doing something like the above possible pre-Swift 3?

Thanks

Simon

Your example is missing the definition of MyProtocol, which is kinda important I think (-:

Share and Enjoy

···

On 4 Mar 2016, at 16:07, Simon Pilkington via swift-users <swift-users@swift.org> wrote:

I was trying to do something like below in Xcode 7.2.1-

--
Quinn "The Eskimo!" <http://www.apple.com/developer/&gt;
Apple Developer Relations, Developer Technical Support, Core OS/Hardware