Programmer ramble (night edition): One dash to rule them all

My co-worker and bag expert (ahem, bag addict?) Ben Brooks recently pointed out this tweet by Federico Viticci in which he was annoyed by the way iOS 11 always creates em-dashes when typing two dashes:

This tweet got me thinking: There must be a way for developers of writing apps to make the lives of users easier when it comes to this. So, I thought about how it might be possible and stumbled upon two possible solutions to this problem.

The basic solution is to disable AutoCorrect on the text field that the user is currently typing in. This can easily be done by subclassing UITextField and overwriting it’s setAutocorrectionType variable to UITextAutocorrectionTypeNo, or by unchecking the box for autocorrection in Interface Builder.

This is a handy solution, but isn’t extremely user-friendly especially for users that rely on autocorrection to type with the on-screen keyboard on iOS devices.

So you can expand on this solution to disable it conditionally. When the UITextFieldDelegate gets a “-” (dash) character typed, disable autocorrection, then re-enable it after a non dash character is typed. This would prevent iOS from automatically converting the double dash into an em-dash.

Finally, this last solution is perhaps the better solution entirely for the user. Writing apps should give users the ability to specify what type of dash style they want. The app could then check the UITextField for any types of dash, and replace the text with the user’s preferred dash style (em-dash, en-dash, double-dash, triple-double-dog-dash, etc.).

This would provide the best user experience, and is something that Apple should be doing as a setting for iOS — they should allow the user to choose the dash style globally. But, if iOS 11 ships with this feature enabled, there will be many unhappy users of text editing apps.

Update: Greg Pierce (creator of Drafts for iOS) replied with another good solution for combating this issue with iOS 11:

The Objective Developer is a blog written by Cory Bohon