100 Days of SwiftUI
2026-05-17
Project 5, part 1
“the last easy project we have on this course”

Lists, strings, and Unicode oh my!
Word Scramble: Introduction
“Word Scramble” — find the anagrams in a word game
Introducing List, your best friend
- while you many not use
Listthe most, you will rely on it the most Listprovides a scrollable table of data for presentation (unlikeFormwhich allows for data entry) —Formis a specializedList- can mix static and dynamic rows in a list
- can
Sectionlists - can generate its rows entirely from dynamic content without needing a
ForEach, e.g.List(0..<5) {Text("Dynamic row \($0)")}
Loading resources from your app bundle
- bundles are used to hold everything about the app
- it’s common to put “extra” files in your bundle that your app will need
- find the file using it’s
URL(i.e. Uniform Resource Locator) - need to use
URLbecause the OS paths are impossible to guess - use
Bundle.main.url()— if the file exists, it will be returned, otherwise it will returnnil - once you have the file as a
Stringyou can do stuff with it
func testBundles() {
if let fileURL = Bundle.main.url(forResource: "some-file", withExtension: "txt") {
// we found the file in our bundle!
if let fileContents = try? String(contentsOf: fileURL){
// we loaded the file into a string!
}
}
}Working with strings
- can do a lot of things with strings
- split into an array
- remove whitespace
- spellcheck
- once the string is in an array (however you’ve split it) you can return a
.randomElement()(which returns an optional string) - use
.trimmingCharacters(in: .whitespacesAndNewlines)from theCharacterSetstruct so remove all the whitespace - use the “slightly unwieldy”
UITextCheckerfor spellcheck - Swift understands e.g. emoji (i.e. UTF16), but Objective-C doesn’t so this is the fiddly part
UITextCheckerwill returnNSNotFoundif there are no misspellings
func testStrings() {
let word = "swift"
// get an instance of the UITextChecker
let checker = UITextChecker()
// let UITextChecker know the encoding
let range = NSRange(location: 0, length: word.utf16.count)
// where was the misspelled word found
let misspelledRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")
// if there wasn't a misspelled word, UITextChecker returns `NSNotFound`
let allGood = misspelledRange.location == NSNotFound
}