Search code examples
arraysdictionaryswift3func

Swift 3 Function Parameter (Dictionary - Array)


I'm using Eureka for my upload form. And I have a UPLOAD button, like this:

<<< ButtonRow() {
    $0.title = "UPLOAD";
}.onCellSelection { cell, row in
    var formValues = self.form.values();
    formValues["userId"] = UserDefaults.standard.string(forKey: "userId");
    self.upload(parameters: formValues); // <- How do I us formValues ?
}

I'm getting this error:

Cannot convert value of type '[String : Any?]' to expected argument type 'Array'

And I have upload() function:

func upload(parameters: Array<Any>) { // <- formValues?
    print(parameters);
}

I don't know formValues is Dictionary or Array? Anyway, how do I pass this parameters to this my function?


Solution

  • It looks like formValues is of type Dictionary not Array. Change your upload function parameters to this:

    func upload(parameters: [String: Any?]) {
        print(parameters);
    }