user2636197 user2636197 - 1 year ago 122
Swift Question

swift ios append elements to array

I have an array that looks like this:

var parameters: [String: AnyObject] = [
"title": "something",
"type": "1"

How do I append something like this:

"someNewField": "someValue"

So that the array would end up like:

parameters: [String: AnyObject] = [
"title": "something",
"type": "1",
"someNewField": "someValue"

Answer Source

This is a dictionary not an array. To append something new to it you would do something like this:

parameters["someNewField"] = "someValue"

Here you can find more documentation on arrays, dictionaries, and their differences:

Also this is a possible duplicate of:

How to append elements into dictionary in swift?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download