title: Counting lines in Swift
body: <p>Apple's <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextLayout/Tasks/CountLines.html" rel="nofollow">Text Layout Programming Guide</a> contains the following fragment of Objective-C code to count the number of lines in an NSString.</p>
  
  <pre><code>NSString *string;
  unsigned numberOfLines, index, stringLength = [string length];
  for (index = 0, numberOfLines = 0; index &lt; stringLength; numberOfLines++)
      index = NSMaxRange([string lineRangeForRange:NSMakeRange(index, 0)]);
  </code></pre>
  
  <p>What would the Swift equivalent be using native String?</p>