NEW: Master Swift design patterns with my latest book! >>

< 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.
  5. Our code shuffles the complete array of words then picks one every time the startGame() method is called. Can you make the game shuffle the array only once, then use an increasing integer property to read different words each time startGame() is called?

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.

Build for watchOS

Take your existing Swift skills to Apple's tiniest platform – check out Hacking with watchOS!

< Previous: Or else what?   Next: Project 6 >
Click here to visit the Hacking with Swift store >>