Dynamic Func Parameters ?

My appologies for posting so much recently.


Just having a mess around and probably far off from a decent result but if you get the idea of what I'm looking for then would appreciate a reply ...


public enum anEnum {
    typealias thisway = (from: URL, to: URL)
    typealias thatway = Bool
}

static func test(_ aliashere: anEnum) {
    let this = aliashere...
}

let this: anEnum.thisway = (from: URL(fileURLWithPath: ""), to: URL(fileURLWithPath: ""))
self.test(this)

Replies

When you declare nested types, they have nothing to do with the enclosing type. Just one thing that you need prefixing the name.


Given this definition: (you should better follow the widely accepted convention - Swift types start with capital letter.)

public enum AnEnum {
    typealias Thisway = (from: URL, to: URL)
    typealias Thatway = Bool
}

Both `AnEnum.Thisway` and `AnEnum.Thatway` are completely different type than `AnEnum`. Any value of type `AnEnum.Thisway` is not valid as `AnEnum`, neither `AnEnum.Thatway`.


You can write something like this:

public enum AnEnum {
    case thisway(from: URL, to: URL)
    case thatway(Bool)
}

class MyFunc {
    static func test(_ aliashere: AnEnum) {
        let this = aliashere//...
    }

    static func anotherMethod() {
        let this = AnEnum.thisway(from: URL(fileURLWithPath: ""), to: URL(fileURLWithPath: ""))
        self.test(this)
    }
}

Thanks but even with capital letters self.test(this) still has an error "Cannot convert value of type '(from: URL, to: URL)' to expected argument type 'AnEnum'".

Is there any other way to have 1 function but 2 sets of parameters ? This is only an experiment.

Please show the exact code which produces the error "Cannot convert value of type '(from: URL, to: URL)' to expected argument type 'AnEnum'".


I cannot reproduce the same issue, and you may have some typo or other mistakes.

I do not understand what sort of experiment are you trying. Please clarify.

Already have.

Oh, I see. You are not talking about my code.

For example if there are 2 functions but share a lot of similar code so it would seem effective to merge them, however calling one function with either lots of default values or just nils for the parameters not needed to be able to call the one function but with 2 different sets of parameters.

For me, it seems not. But if you could show some example of such merging would work fine, I would change my mind.

Just thinking generally not got anything specific, only wondering if it's possible.

Is there any other way to have 1 function but 2 sets of parameters ? This is only an experiment.


So, that will be 2 different functions, because not the same signature.