Language is complicated.
One of my favorite TV comedies is called Blackadder, and featured a conversation between Dr Samuel Johnson (who had recently finished his dictionary of the English language), and Blackadder (butler to Prince George):
Samuel Johnson: “Here it is, sir. The very cornerstone of English scholarship. This book, sir, contains every word in our beloved language.”
Blackadder: “Every single one, sir?”
Samuel Johnson: “Every single word, sir!”
Blackadder: “Oh, well, in that case, sir, I hope you will not object if I also offer the doctor my most enthusiastic contrafibularities.”
Samuel Johnson: “What?”
Blackadder: “Contrafibularities, sir? It is a common word down our way.”
Samuel Johnson: “Damn!” [adds it to his dictionary]
Blackadder: “Oh, I'm sorry, sir. I'm anaspeptic, phrasmotic, even compunctuous to have caused you such pericombobulation.”
We can see further evidence of how complicated language is by looking at the way Swift handles strings. Have you ever wondered why you can’t read individual letters from strings using integer positions? In code, this kind of thing isn’t built into Swift:
let letter = someString
The reason for this is that Swift uses a rather complicated – but extremely important! – system of storing its characters, known as extended grapheme clusters. This means for Swift to read character 8 of a string it needs to start at 0 and count through individual letters until it reaches the 8th one; it can’t jump straight there.
As a result, Swift doesn’t let us use
str to read the 8th character – even though they could enable such behavior trivially, it could easily result in folks using integer subscripting inside a loop, which would have terrible performance.
All this matters because today you’re going to be using
UITextChecker to check whether a string is spelled correctly. This comes from UIKit, which was written in Objective-C, so we need to be very careful how we give it Swift strings to use.
Today you have three topics to work through, and you’ll learn about using
UITextChecker to find invalid words, inserting table view rows with animation, and more.
Need help? Tweet me @twostraws!
SPONSORED Build a functional Twitter clone using APIs and SwiftUI with Stream's 7-part tutorial series. In just four days, learn how to create your own Twitter using Stream Chat, Algolia, 100ms, Mux, and RevenueCat.
Sponsor Hacking with Swift and reach the world's largest Swift community!
The 100 Days of Swift is a free collection of videos, tutorials, tests, and more to help you learn Swift faster. Click here to learn more, or watch the video below.
Link copied to your pasteboard.