title: How to get the value of an array of selected keys from swift array of dictionaries and the complexity of it
body: <p>Lets say I have got the below response. Two things I would like to know from the below operation. </p>
  
  <p>1.) How to improve/optimise the below code using higher order functions in swift. </p>
  
  <p>2.) Also would like to know the current complexity of the code and the complexity of any optimized code you may suggest.</p>
  
  <p>In the below response I would like to check the values of only certain keys as described in keysToBeChecked and for that particular key I need to do an operation. Once the operation is done I want to add a new key(key6) to the response as shown below. The following operation works fine for me and that is what I intend to do. I am looking for the above 2 things mentioned</p>
  
  <pre><code>var response = [["key1": 1, "key2": 0, "name": "John", "key3": 1, "key4": 1, "place": "Newyork", "key5": 0],
                  ["key1": 0, "key2": 1, "name": "Mike", "key3": 1, "key4": 0, "place": "California", "key5": 1],
                  ["key1": 1, "key2": 0, "name": "John", "key3": 0, "key4": 1, "place": "Boston", "key5": 1]]
  </code></pre>
  
  <pre class="lang-swift prettyprint-override"><code>let keysToBeChecked = ["key1", "key2", "key3", "key4", "key5"]
  
  for var item in response{
  var dict = [String: String]()
     for(key, value) in item{
         if keysToBeChecked.contains(key){
             dict[key] = "\(value)"
             if dict[key] == "1"{
                 //perform required operations
                 output
             }
         }
     }
  
     item["key6"] = output
     response.append(item)
  }
  print(response)//should print the below
  
  
  My expected output is
  
  response = [["key1": 1, "key2": 0, "name": "John", "key3": 1, "key4": 1, "place": "Newyork", "key5": 0, "key6": "output"],
     ["key1": 0, "key2": 1, "name": "Mike", "key3": 1, "key4": 0, "place": "California", "key5": 1, "key6": "output"],
     ["key1": 1, "key2": 0, "name": "John", "key3": 0, "key4": 1, "place": "Boston", "key5": 1, "key6": "output"]]
  </code></pre>