title: How to build an array of dictionaries depending on the values of a certain model
body: <p>I have a type alias of <code>[String:Any]</code></p>
  
  <pre><code>public typealias Parameters = [String:Any]
  </code></pre>
  
  <p>And i have a computed property that will build these parameters from the model values.</p>
  
  <pre><code>var parameters: Parameters {
      switch self {
      case .addOFFProduct(let product):
          var parameters: Parameters!
          let code = product.code!
          let username = product.username
          let password = product.password
          if let productName = product.productName, let genericName = product.genericName, let countriesText = product.countriesText, let brandsText = product.brandsText, let storesText = product.storesText, let ingredientText = product.ingredientText, let quantity = product.quantity, let additivesText = product.additivesText, let categoriesText = product.categoriesText {
              parameters = [
                  Constants.OffProduct.code:        code,
                  Constants.username:               username,
                  Constants.password:               password,
                  Constants.OffProduct.productName: productName,
                  Constants.OffProduct.genericName: genericName
              ]
          }
          return parameters
      }
  }
  </code></pre>
  
  <p>Now I need to build the parameters type according to the production values if they are nil then it won't be added in the <code>[String:Any]</code>.
  For example, if <code>generic name</code> is <code>nil</code> and all others are not then the parameters will be like follows</p>
  
  <pre><code>parameters = [
      Constants.OffProduct.code:        code,
      Constants.username:               username,
      Constants.password:               password,
      Constants.OffProduct.productName: productName
      //GENERIC NAME REMOVED
  ]
  </code></pre>
  
  <p>How can I achieve a logic likes this. Im confused. Thanks</p>