luke
luke

Reputation: 2773

Attempting to append a value to a dictionary

Trying to append a value to a dictionary

public typealias Parameters = [String: Any]

   var parameters: Parameters = [
        "username" : username,
        "first_name" : firstName,
        "last_name" : lastName,
        "profession" : profession
    ]
    if let imageURl = imageUrl {
        parameters[4] = ["image_url" : imageUrl]
    }

I get back ambiguous reference to member 'subscript' at line parameters[4] = ["image_url" : imageUrl]

How can I solve this?

Upvotes: 1

Views: 67

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726809

You should access parameters dictionary by its String key, i.e. "image_url", not by its index 4:

if let imageURl = imageUrl {
    parameters["image_url"] = imageUrl
}

Upvotes: 3

Related Questions