1

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"
            ]
1
  • This might be a use-case better suited for Structs, just by judging from the Dictionary keys. Commented Aug 15, 2016 at 23:42

1 Answer 1

4

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:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html

Also this is a possible duplicate of:

How to append elements into dictionary in swift?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.