user2722667
user2722667

Reputation: 8651

Swift 3 [String: AnyObject]() gives Cannot call value of non-function type UInt -> Data

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

Upvotes: 0

Views: 329

Answers (1)

Swifty
Swifty

Reputation: 3760

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)!)
}

Upvotes: 1

Related Questions