100 Days of SwiftUI

Day 30

2026-05-18

Project 5, part 2

I promise to stop at the end of today’s lesson 🙃

Adding to a list of words

  • to begin with, just collect the list of words they enter — later we’ll add validation
  • .onSubmit() is a modifier on the List that runs a method
    • it takes no parameters (save the name of the func) and returns nothing
    • keyboard Return or Enter will trigger it, so no need for a button
  • auto-capitalization (and auto-correct!) can be disabled on TextFields
  • withAnimation when the wordlist is modified is a nice little touch

Running code when our app launches

  • creating a func that will load the main word list (a text file)
    • it will see if it’s there
    • it will see if it’s valid
    • if not it will send a fatalError() message
  • a modifier on the List (.onAppear(perform: startGame)) will cause the func to run when the view appears (i.e. when we see the screen of the app)
Tip

The placement of the view modifiers is really important! I had them on the NavigationStack but never saw the word to search. When I moved them to the List it worked as expected

Validating words with UITextChecker