0

I am trying to append some parameters to my Alamofire request.

var parameters = [String: AnyObject]()

parameters["firstimg"] = fetchedImagesArray[0] as AnyObject?

parameters["secondimg"] = fetchedImagesArray[1] as AnyObject?

Then:

    for (key, value) in parameters {
        multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}

But when I try to append the parameters I get the error: Cannot call value of non-function type UInt -> Data

5
  • FYI Alamofire Parameters default to [String: Any] not [String: AnyObject] Commented Oct 5, 2016 at 18:50
  • @Aaron how should I declare var parameters = [String: AnyObject]() then? Commented Oct 5, 2016 at 18:58
  • var parameters: [String: Any]? Commented Oct 5, 2016 at 19:16
  • what is in the fetchedImagesArray? Strings? Commented Oct 5, 2016 at 19:26
  • @Sam_M Yes they are strings Commented Oct 5, 2016 at 19:56

1 Answer 1

1

You need to cast value as String to use the data(using: .utf8) method on it:

if let stringValue = value as? String {
    multipartFormData.append(stringValue.data(using: String.Encoding.utf8)!)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.