NEW! Pre-order my latest book, Testing Swift! >>

< Previous: Or else what?   Next: Project 6 >

Wrap up

You've made it this far, so your Swift learning really is starting to come together, and I hope this project has shown you that you can make some pretty advanced things with your knowledge.

In this project, you learned a little bit more about UITableView: how to reload their data and how to insert rows. You also learned how to add text fields to UIAlertController so that you can accept user input. But you also learned some serious core stuff: more about Swift strings, closures, method return values, booleans, NSRange, and more. These are things you're going to use in dozens of projects over your Swift coding career, and things we'll be returning to again and again in this series.

You may already have plans for how you'd like to improve this game, but if not here are some ideas to get you started:

  1. Disallow answers that are shorter than three letters. The easiest way to accomplish this is to put a check into isReal() that returns false if the word length is under three letters. If you don’t want to do that, at least disallow empty strings!
  2. Refactor all the else statements we just added so that they call a new method called showErrorMessage(). This should accept an error message and a title, and do all the UIAlertController work from there.
  3. Disallow answers that are just the start word. Right now, if the start word is "agencies" the user can just submit "agencies" as an answer, which is too easy – stop them from doing that.
  4. Fix our start.txt loading code. If the path(forResource:) call returns nil we load an array containing one word: silkworm. But what if path(forResource:) succeeds, but creating a String using contentsOfFile fails? Then the array is empty! Make a new loadDefaultWords() method that can be used for both failures.

You did it! Now what?

You finished another project, and I'm glad Hacking with Swift helped you. Now I need your help. Please take just a moment out of your day to tell others about Hacking with Swift so they can benefit too.

You can click below to post a tweet straight to this project. Or if you're feeling particularly generous, you can click here to link to Hacking with Swift on your website and help spread the word.

Thank you. Your support is what keeps me going!

 

About the author

Paul Hudson is the creator of Hacking with Swift, the most comprehensive series of Swift books in the world. He's also the editor of Swift Developer News, the maintainer of the Swift Knowledge Base, and Mario Kart world champion. OK, so that last part isn't true. If you're curious you can learn more here.

Download for free!

Want a free 75-minute video teaching functional programming, protocol-oriented programming, and more? This is your lucky day!

< Previous: Or else what?   Next: Project 6 >
MASTER SWIFT NOW
Buy Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let me know!

Click here to visit the Hacking with Swift store >>