title: How to get the number of real words in a text in Swift
body: <p>Edit: there is already a question similar to this one but it's for numbers separated by a specific character (<a href="https://stackoverflow.com/questions/30679564/get-no-of-words-in-swift-for-average-calculator">Get no. Of words in swift for average calculator</a>). Instead this question is about to get the number of real words in a text, separated in various ways: a line break, some line breaks, a space, more than a space etc.</p>
  
  <p>I would like to get the number of words in a string with Swift 3.</p>
  
  <p>I'm using this code but I get imprecise result because the number is get counting the spaces and new lines instead of the effective number of words.</p>
  
  <pre><code>let str = "Architects and city planners,are  \ndesigning buildings to create  a better quality of life in our urban    areas."
  // 18 words, 21 spaces, 2 lines
  
  let components = str.components(separatedBy: .whitespacesAndNewlines)
  
  let a = components.count
  
  print(a)
  // 23 instead of 18
  </code></pre>