1

I am creating a xCode/Swift project with .json.

I want to create an array of keys, and also a boolean(true/false) to mark if the key is used or not. Standard boolean value is false. And if the key is used, it updates to true. I am not sure how to do this, but I have tried something like this:

{
    "aloUrl": "fb://profile/********",
    "imgAD_active": true,
    "keys"{
        "key_red": false // if key "key_red" is used, set to true
        "key_green": false
        "key_black": false
        "key_white": false
        "key_orange": false
        "key_pink": false
    }
}

How do I do this?

Donmar
  • 11
  • 2

1 Answers1

0

you can use dictionary contains of String as keys and Any as values

let dic: [String: Any]
dic["aloUrl"] = "fb://profile/********"
dic["imgAD_active"] = true
dic["keys"] = ["key_green": false, "key_red": false, ...]

I also retrieve values as

let url = dic["aloUrl"] as? String
Hady Nourallah
  • 442
  • 4
  • 12
  • What should my `.json` file look like? – Donmar Jun 06 '17 at 13:31
  • then you may check this one https://stackoverflow.com/a/29625483/1485833 to convert it to a JSON string. after that you might want it to store it into .json file you can look at this for reading and writing to a file https://stackoverflow.com/a/24098149/1485833 – Hady Nourallah Jun 06 '17 at 13:33