-4

I have a string: Any array, like this

public var parameters: [String: Any] = [
    "myParameters": "all",
    //"fromDate": Date = Date()
    //"searchByName": String = ""
]

I would like to add value "sampleValue" to the default value "all", so the array looks like this.

[
  "parameterSetOne": "all, sampleValue",
  "parameterSetTwo" : 20.00,
   "parameterSetThree" : date(),
]
ChrisF
  • 134,786
  • 31
  • 255
  • 325
JIANG
  • 1,687
  • 2
  • 19
  • 36
  • I had the results of "myParameters": ["all", "sampleValue"], this results needs to be part of a API payload. with bracket it is not accepted by the API call. Only this format is accepted . "myParameters": "all", "sampleValue" – JIANG Mar 24 '21 at 15:27
  • 1
    That's not a valid kind, valid JSON or else. It means that you have to build it yourself, but it's strange that your API have a strange format. – Larme Mar 24 '21 at 15:27
  • @Larme, can you please elaborate on that? I will bring it to the backend developer and ask for an explanation. Thanks for look into this. – JIANG Mar 24 '21 at 16:33
  • 1
    Your back-end developer expects JSON or not? if yes, copy/paste `["myParameters": "all", "sampleValue"]` into a JSON validator (plenty online tools) you'll see. And if you back-end developer really expects JSON, he/she needs to give your a real example. What you gave is strange, and in coding, each char is important, so please be careful. I answered on the other question what could be done, but that's GUESSING that's the deisred output. – Larme Mar 24 '21 at 16:34
  • @Larme, I think you got the answer, the backend developer is expecting "parameterSetOne": "all, sampleValue" – JIANG Mar 24 '21 at 16:36
  • @Larme, thank you for your time and your help! If you put your response as the answer, I will mark it as answer. – JIANG Mar 24 '21 at 16:37
  • 1
    ` the backend developer is expecting "parameterSetOne": "all, sampleValue"` finally! Be careful next time, you'll loose time (both yours and ours) with misleading informations ;) – Larme Mar 24 '21 at 16:38
  • @Larme, totally agree, only if they give me an example what to expected from the front instead of let me doing the guessing game. – JIANG Mar 24 '21 at 16:40
  • 1
    [Question](https://stackoverflow.com/questions/24034174/how-do-i-concatenate-strings-in-swift) about concatenating strings – Joakim Danielson Mar 24 '21 at 17:50

1 Answers1

1
parameters["parameterSetOne"] = parameters["parameterSetOne"] as! String + " sampleValue"

But you have to make sure that it is really a String value in "parameterSetOne"

Christoph S.
  • 585
  • 3
  • 16