Day 31 Completed

I finished day 31. For some reason my rootWords were coming in as having one more character than they should have had. I don’t remember having this problem the first time I did this app. It showed up as a problem when I was checking to see if someone used the rootWord as their guess for the new word.

I was able to fix it by adding the .trimmingChareacters(in: .whitespacesAndNewlines). I checked Paul’s code and didn’t see it in there, but mine seemed to need it.

if let startWordsUrl = Bundle.main.url(forResource: "start", withExtension: "txt") {
            if let startWords = try? String(contentsOf: startWordsUrl) {
                let allWords = startWords.components(separatedBy: "\n")
                rootWord = allWords.randomElement()?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "silkworm"
                return
            }
        }

Originally posted on Jan 13, 2022 on hackingwithswift.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s