How to get the position of the elements in TextField in swift

advertisements

How to get the position of items in TextField in swift. I have "255.789" text in textField. How can i get the position of "."(decimal point ) in swift.


Here is a simple way you could get it

if let t = textField.text
{
  let dotPos = t.rangeOfString(".")?.endIndex.predecessor()
}

Just keep in mind the dotPos is an optional that needs to be unwrapped before use