Day 38
Day 38 관련
Project 8, part three
There are many well-known quotes from Shakespeare, but there’s one I think is particularly apt today: “the fool doth think he is wise, but the wise man knows himself to be a fool.” I don’t know where you’d rank yourself in terms of Auto Layout knowledge, but I hope you’re at least aware that it’s a really big, complex space to work in!
In my talk at NSSpain 2018 I said “Auto Layout makes hard things easy, and easy things hard” – you’ll find you can do relatively advanced layouts like today’s in about an hour, but occasionally you’ll find yourself wanting one specific layout constraint that is really hard to get right.
Fortunately for all of us, this part of your Auto Layout learning is complete, so it’s time for us to review what you’ve learned.
Today you should work through the wrap up chapter for project 8, complete its review, then work through all three of its challenges.
Wrap up
Wrap up
Yes, it took quite a lot of user interface code to get this project going, but I hope it has shown you that you can make some great games using just the UIKit tools you already know. Building user interfaces programmatically is obviously much less visual than using storyboards, but the flip side is that everything is under your control – there are no connections happening behind the scenes.
Of course, at the same time as making another game, you've made several steps forward in your iOS development journey, this time learning about addTarget()
, enumerated()
, joined()
, replacingOccurrences()
, and more.
Review what you learned
Anyone can sit through a tutorial, but it takes actual work to remember what was taught. It’s my job to make sure you take as much from these tutorials as possible, so I’ve prepared a short review to help you check your learning.
Click here to review what you learned in project 8.
Challenge
One of the best ways to learn is to write your own code as often as possible, so here are three ways you should try extending this app to make sure you fully understand what’s going on:
- Use the techniques you learned in project 2 to draw a thin gray line around the buttons view, to make it stand out from the rest of the UI.
- If the user enters an incorrect guess, show an alert telling them they are wrong. You’ll need to extend the
submitTapped()
method so that iffirstIndex(of:)
failed to find the guess you show the alert. - Try making the game also deduct points if the player makes an incorrect guess. Think about how you can move to the next level – we can’t use a simple division remainder on the player’s
score
any more, because they might have lost some points.
Wrap up - Additional
Once you’re done, tell other people: you’ve built another great app for iOS, and you’ve learned how to build a complete user interface entirely in code.
You should be proud of what you’ve accomplished – keep it up!