Swift Types and dynamic type comparisons

So I've got a typing problem that I'm unsure how to solve under Swift 3. I've tried several approaches only to be whacked by the compiler.


This is quite complex, but I'll make an effort at distilling the problem down to something that will fit in a forum post:


I have a protocol

protocol Parameter { }


To which several various types conform.


I have a cluster of types which accept initialization by

class SomeType: Parametric {

    init(params: [ParamKey: Parameter]) {
          ...
    }

}

('ParamKey' is mostly just a String)


Please note that this initialization pattern is a central requirement of the application domain, not an attempt at circumventing Swift initialization!


When the user executes a command which may result in one of these types being created, a series of args are populated by user-entered strings. There are different argument types which are each responsible for parsing the incoming strings into values which satisfy the argument. It's important to note that not every argument must result in a 'Parameter' type, and those that do, may parse the input into any number of types conforming to 'Parameter'.


When the command's arguments are all satisfied, the application executes the command against the arguments. The command function is responsible for extracting the values it needs from the command arguments. Because some commands can execute with different types, but have an inherent preference, I need to write a function on CommandArgument which extracts the value based on this preference:


    public func parameterValue(with priority: [Parameter.Type]) -> Parameter?


Now this is fairly straight-forward to solve in the base case.


However, one special case of argument stores its value in an internal struct, because the argument parsing may result in more than one potential value and I want to maintain that potential until the value is extracted:


private struct PointValue: CommandArgValue {

    var markRef: Mark?
    var xyLiteral: PointType?
    var concretePoint: PointType?
    var pointRef: OArcDOM.Point?

     ...


Now the problem is that I can't figure out how to implement my parameterValue(with priority) method.


    override public func parameterValue(with priority: [Parameter.Type]) -> Parameter? {
        for aType in priority {
            switch aType {
            case is Mark.self where parsedPointValue?.markRef != nil:
                return parsedPointValue?.markRef
            /// ... and so on
            }
        }
        return nil
    }


Every mechanism I've tried to compare the types in priority with a literal type cause some sort of compiler error or warning:


// Not an exhaustive list of things I've tried:
case is Mark.self: /// Cast from 'Parameter.Type' to unrelated type 'Mark' always fails
case Mark.Type: /// Expression pattern of type 'Mark.Type' cannot match values of type 'Parameter.Type'


I've also tried using Mirror, which I think is likely the more correct approach, but its not clear to me from the docs what the right way to use this structure is, espciallially in conjunction with protocols.


It's worth noting that I'd also like to be able to have this function make "as" comparisons instead of "is" comparisons.. that is, if one passes a super-type of the concrete type of the element I'm testing against, I'd like the test to pass.


Any help or pointers (no pun intended) would be appreciated.