12

I've an NSTextView with with several semi-colon separated strings. I need to find on which of those strings the caret has been placed. How could I do that?

ruipacheco
  • 15,025
  • 19
  • 82
  • 138

2 Answers2

31
NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
Art Gillespie
  • 8,747
  • 1
  • 37
  • 34
3

For Swift 4

let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
Jay Mehta
  • 1,511
  • 15
  • 20