Setting up
Setting up êŽë š
Projects 1 to 4 were all fairly easy, because my goal was to teach you the basics of iOS development while also trying to make something useful. But now that you're hopefully starting to become familiar with the core tools we have, it's time to change up a gear and tackle something a bit harder.
In this project you're going to learn how to make a word game that deals with anagrams, but as per usual I'll be hijacking it as a method to teach you more about iOS development. This time around we're going back to the table views as seen in project 1, but you're also going to learn how to load text from files, how to ask for user input in UIAlertController
, and get a little more insight to how closures work.
In Xcode, create a new Single View App called Project5. Weâre going to turn this into a table view controller, just like we did in project 1. So, open ViewController.swift
and find this line:
class ViewController: UIViewController {
Please change it to read this instead:
class ViewController: UITableViewController {
If you remember, that only changes the definition of our view controller in code. We need to change in the storyboard too, so open Main.storyboard
now.
Inside Interface Builder, use the document outline to select and delete the existing view controller so that the document is blank, then replace it with a new table view controller. Use the identity inspector to change the class of the new controller to be âViewControllerâ, then select its prototype cell and give it the re-use identifier âWordâ and the cell style Basic.
All this was covered in project 1, but itâs OK if you forgot â donât be afraid to go back to project 1 and re-read any bits youâre not sure about.
Now select the view controller again (use the document outline â itâs easier!) then make sure the âIs Initial View Controllerâ box is checked under the attributes inspector. Finally, go to the Editor menu and choose Embed In > Navigation Controller. We wonât be pushing anything onto the navigation controller stack like we did with project 1, but it does automatically provide the navigation bar at the top, which we will be using.
Note
This app asks users to make anagrams out of a word, e.g. when given the word âanagramsâ they might provide âragsâ. If you look at that and think âthatâs not an anagram â it doesnât use all the letters!â then you need to search the internet for âwell actuallyâ and have a good, long think about life.