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:
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!
elsestatements 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
UIAlertControllerwork from there.
nilwe load an array containing one word: silkworm. But what if
path(forResource:)succeeds, but creating a
contentsOfFilefails? Then the array is empty! Make a new
loadDefaultWords()method that can be used for both failures.
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!
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!