BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

DAY 28

Project 5, part two


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[5]

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[7] 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!

 

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

100 Days of Swift


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.

Back to 100 Days of Swift

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.