title: How to sort an array by a specific key
body: <p>I am using swapi.co as my source of json data and my response looks like the following: <a href="https://swapi.co/api/people/" rel="nofollow noreferrer">https://swapi.co/api/people/</a></p>
  
  <p>My array of "characters" has the structure</p>
  
  <pre><code>// MARK: - CharactersResult
  struct CharactersResult: Codable {
      let name, height, mass, hairColor: String
      let skinColor, eyeColor, birthYear: String
      let gender: Gender
      let homeworld: String
      let films, species, vehicles, starships: [String]
      let created, edited: String
      let url: String
  
      enum CodingKeys: String, CodingKey {
          case name, height, mass
          case hairColor = "hair_color"
          case skinColor = "skin_color"
          case eyeColor = "eye_color"
          case birthYear = "birth_year"
          case gender, homeworld, films, species, vehicles, starships, created, edited, url
      }
  }
  </code></pre>
  
  <p>I would like to get the <strong>smallest</strong> character and the <strong>largest</strong> out of my array. My function is:</p>
  
  <pre><code>func getCharacters(urlToGet: String){
              do{
                  if let url = URL(string: urlToGet) {
                      URLSession.shared.dataTask(with: url) { data, response, error in
                          if let data = data {
                              do {
                                  let jsonCharacters = try JSONDecoder().decode(Characters.self, from: data)
  
  
  
                                  self.characters = self.characters + jsonCharacters.results
  
                                  self.nextPageUrlForCharacters = jsonCharacters.next
  
                                  self.updatePicker()
  
                              } catch let error {
                                  print(error)
  
  
                              }
                          }
                          }.resume()
  
                  }
              }
          }
  </code></pre>
  
  <p>My main question is where to do the sorting and what is the most efficient way to get the smallest and the largest character.</p>