Search code examples
stringswiftnsstringrangensrange

How to compare a .startIndex of Range<String.Index>


I'm receiving a Range String.Index from the rangeOfString-method.

searchParagraphs = ress.rangeOfString("\n")

now i want to proof the position of the startIndex:

if searchParagraphs?.startIndex == 0 {}

it's not working, because "String.Index? does not conform to protocol _RawOptionSetType". so how can i proof the position/startIndex of a String.Index?


Solution

  • To check for the initial position, the correct way is:

    if searchParagraphs?.startIndex == ress.startIndex {}