title: String.enumerateSubstringsInRange in Swift with stop
body: <p>At first, thanks for Stonz2's answer in <a href="https://stackoverflow.com/questions/28764651/find-last-visible-line-index-in-nsattributedstrings-drawwithrect">Find last visible line index in NSAttributedString&#39;s drawWithRect</a> </p>
  
  <p>I have a similar trouble, so i got this objective-c function.</p>
  
  <p>But i'm using swift, when i want to convert this to swift, i got trouble.</p>
  
  <p>Here is a swift version of Stonz2's answer i'm just converted.</p>
  
  <pre><code>func removeLastWord( str:String ) -&gt; String{
      var range = Range(start:count(str), end:0)
      let opts:NSStringEnumerationOptions = .ByWords | .Reverse | .SubstringNotRequired
  
      // trouble in here,  Cannot invoke 'enumerateSubstringsInRange' with an argument list of type '(Range&lt;Int&gt;, options: NSStringEnumerationOptions, (_, _, _, _) -&gt; ())'
      str.enumerateSubstringsInRange(Range(start:0, end:count(str)), options: opts) {
          (substring, substringRange, enclosingRange, stop) -&gt; () in
          range = substringRange
          stops = true
      }
  
      return str.substringToIndex(advance(str.startIndex, range.endIndex))
  }
  
  func pageSplitIndexForString( string:String, frame:CGRect, font:UIFont ) -&gt; Int {
  
      let fixedWidth = frame.size.width
      let textView = UITextView()
  
      textView.text = string
      textView.font = font
  
      var newSize = CGSizeMake(fixedWidth, CGFloat.max)
      textView.frame.size = newSize
      textView.sizeToFit()
      var newFrame = textView.frame
  
      println(textView.frame)
  
      while ( newFrame.height &gt; frame.height ) {
          textView.text = removeLastWord(textView.text)
          newSize = CGSizeMake(fixedWidth, CGFloat.max)
          textView.frame.size = newSize
          textView.sizeToFit()
          // fmaxf fmax?
          newFrame.size = CGSizeMake(fmax(newSize.width, fixedWidth), newSize.height)
      }
  
      var str = string.substringFromIndex(advance(textView.text.startIndex, count(textView.text)))
  
      println("Page one text: \(textView.text)")
      println("Page two text: \(str)")
  
      return (textView.text as NSString).length
  }
  </code></pre>
  
  <p>So i want know what's the correct way to convert this objective-c function in swift?</p>