title: Swift get first letter from property in array of custom objects
body: <p>I have a custom object</p>
  
  <pre><code>class Keyword
  {
      var keyword : String
      var description : String
  
      init(keywordID : Int, keyword : String, description : String)
      {
          self.keyword = keyword;
          self.description = description;
      }
  }
  </code></pre>
  
  <p>And its data's like</p>
  
  <pre><code>var keywords = [Keyword]()
  keywords.append(Keyword(keyword: "abc", description: "dsd dfgdf dghj"))
  keywords.append(Keyword(keyword: "adet", description: "dsd dfgdf dghj"))
  keywords.append(Keyword(keyword: "niuk", description: "dsd dfgdf dghj"))
  keywords.append(Keyword(keyword: "sdg", description: "dsd dfgdf dghj"))
  keywords.append(Keyword(keyword: "sax", description: "dsd dfgdf dghj"))
  keywords.append(Keyword(keyword: "trygh", description: "dsd dfgdf dghj"))
  </code></pre>
  
  <p>For creating sections in UITableView, I need to have the first letter as the section title. For the above example I need the data as below</p>
  
  <ol>
  <li>a -> abc, adet </li>
  <li>n -> niuk </li>
  <li>s -> sdg, sax </li>
  <li>t -> trygh</li>
  </ol>
  
  <p>I created another object to store the above data</p>
  
  <pre><code>class KeywordSection
  {
      var section : Character
      var keywords : [Keyword]
  
      init(section : Character, keywords : [Keyword])
      {
          self.section = section;
          self.keywords = keywords;
      }
  }
  </code></pre>
  
  <p>I did this in Android by looping through the array and extract the first letter and checking the sections. Also I need to check if the first letter is alphabet, if so I have to add that section, else the section will be '#' (same as that of iphone contacts app)</p>