Version one of conversion.

I converted ttippin84’s objective C version of this to swift and fixed
a bug because the textfield was not setting the activeField value
properly.