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.
Merge pull request #1 from dsandor/master

Version one of conversion.