[swift-users] Using ... as a concrete type conforming to protocol ... is not supported

Simon Pilkington simonmpilkington at icloud.com
Fri Mar 4 10:07:23 CST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160304/047ce6cc/attachment.html>


More information about the swift-users mailing list