title: Why Array data is not appending each time with JSON response in Swift
body: <p>My dropdown is array of string type, so i have taken</p>
  <pre><code>var statesArray1 = [String]()//this array values is not changing with corresponding selectedCountry?.id in JSON
  var statesArray = [States]()
  var selectedState: States?
  </code></pre>
  <p>in below code <code>country_id</code> is changing and</p>
  <pre><code>private func getStatesService(){
  
  print(&quot;selected countryid \(selectedCountry?.id)&quot;)
  let parameters: [String : Any] = [&quot;country_id&quot; : selectedCountry?.id]
  APIReqeustManager.sharedInstance.serviceCall(param: parameters as [String : Any], method: .post, loaderNeed: false, loadingButton: nil, needViewHideShowAfterLoading: nil, userInteractionCheck : false,vc: self, url: CommonUrl.get_cities, isTokenNeeded: true, isErrorAlertNeeded: false, isSuccessAlertNeeded: false, actionErrorOrSuccess: nil, fromLoginPageCallBack: nil) {[weak self] (response) in
      
   self?.getStates = StatesDataModel(dictionary: response.dict as NSDictionary? ?? NSDictionary())
          
   for statesData in self?.getStates?.result?.states ?? []{
      
   print(&quot;selected country states \(statesData.state_name)&quot;)
  
   self?.statesArray1.append(statesData.state_name!)
                  
   self?.statesArray.append(States(dictionary: [&quot;adn1code&quot; : statesData.adn1code, &quot;code&quot; : statesData.code, &quot;country_id&quot; : statesData.country_id, &quot;id&quot; : statesData.id, &quot;state_name&quot; : statesData.state_name])!)
     
    }
    }
  </code></pre>
  <p><strong>here if i print <code>selected country states</code> coming correct result but when i print <code>statesArray1</code> showing always only first selected country states why</strong>?.. where as each time countryid is changing and coming correct result</p>
  <p><em>here i am showing all states in dropdown</em> but always showing first selected country states.. please do help to solve this issue</p>
  <pre><code>@IBAction func stateBtn(_ sender: Any) {
  getStatesService()
  
  showDropDown(with: statesArray1, from: sender as! UIButton) { [weak self] (item, index) in
      self?.assignSelectedState(havingTitle: item)
  }
  }
  </code></pre>
  <p>pic one ...  <a href="https://i.stack.imgur.com/VX1Ol.png" rel="nofollow noreferrer">first country and states dropdown coming correctly</a></p>
  <p>second pic.. <a href="https://i.stack.imgur.com/9XkvS.png" rel="nofollow noreferrer">second time i have changed country but still states dropdown showing first selected country states</a></p>
  <p><strong>EDIT:</strong>  total country and states related code</p>
  <pre><code>func assignSelectedCountry(havingTitle: String) {
  for country in self.countrysArray {
      if havingTitle == country.name {
          self.selectedCountry = country
          self.populateData()
          selectedCountryId = self.selectedCountry?.id
      }
  }
  }
  
  func populateData() {
  self.countryTextField.text = self.selectedCountry?.name
  }
  
  @IBAction func countryBtn(_ sender: UIButton) {
  showDropDown(with: countrysArray1, from: sender) { [weak self] (item, index) in
      self?.assignSelectedCountry(havingTitle: item)
  }
  }
  
  func assignSelectedState(havingTitle: String) {
  for state in self.statesArray {
      if havingTitle == state.state_name {
          self.selectedState = state
          self.populateDataforState()
      }
  }
  }
  
  func populateDataforState() {
  self.stateTextField.text = self.selectedState?.state_name
   }
  </code></pre>