1.
One thing, iteration is not needed for this:
for word in words { arrayOfWords += [word] }
You can simply do:
arrayOfWords += words
2.
Aborting the for loop will prevent unnecessary repetition:
for (mistake, word) in autocorrectList { println("The mistake is \(mistake)") if mistake == arrayOfWords.last { fullString = word hasWordReadyToCorrect = true break; // Add this to stop iterating through 'autocorrectList' } }
Or even better, forget completely for the loop:
if let word = autocorrectList[arrayOfWords.last] { fullString = word hasWordReadyToCorrect = true }
Ultimately, what you do is see if the last word of the entered text matches any of the keys in the AutoCorrect list. You can simply try to get the value directly using an optional binding like this.
---
I will let you know if I think more.
Logan source share