Learn Courses My Dashboard

Matching words in language learning app ?!

Hello everyone!
I am working on an app learning languages and I am stumped.

Database has 3 languages, for example:

day | día | 日

Do you notice how in Spanish, the 2nd option, there is an accent on the i?

  1. When a user sees English “day” and is typing input of spanish for day, how do I make the app accept día (WITH an accent on the “i”) ORRR dia (WITHOUT an accent mark on the “i”)???

I would like to tell the app to accept all words in the database if they have a or á, e or é, i or í, o or ó, and u or ú.

  1. Another annoying thing is how if the user taps a word on the keyboard, apple ios automatically adds a space at the end of the word, and if the user hits enter, it counts it as wrong because of the space.

These seem like such simple fixes but I am stumped. Please provide your thoughts!!

Thank you SO much!

You can use the NSString method compare(_:options:) with .diacriticInsensitive to ignore diacritics.

import Foundation
let spanish = "día"
let guess = "dia"

if spanish.compare(guess, options: .diacriticInsensitive) == .orderedSame {
    print("they are the same")
} else {
    print("they are different")
}

Use .trimmingCharacters(in:) to remove leading and trailing whitespace:

let extraSpace = "hello "
print("|\(extraSpace)|")
//prints |hello |
print("|\(extraSpace.trimmingCharacters(in: .whitespacesAndNewlines))|")
//prints |hello|
1 Like

Roosterboy beat me to it. Here is my suggestion for the first issue nevertheless.

If you press and hold the letters that have accented versions, a window will pop up to allow you to select the correct accented character.

1 Like

Awesome - thank you both!!

2 more questions:

1.) How can I accept lowercase letters AND capital letters???

2.) In voice to text, how do I make it deduct that user has ended speaking and now make text of that speech (android was much more simple on this for me!).

You can add .caseInsensitive to the compare options.

if spanish.compare(guess, options: [.diacriticInsensitive, .caseInsensitive]) == .orderedSame {
    print("they are the same")
} else {
    print("they are different")
}

So thankful to you both!!!

As far as doing voice to text matching —

how do I make it deduct that user has ended speaking and now make text of that speech (android was much more simple on this for me!)???

What method are you using to capture the users voice? Obviously you are using the microphone but is the voice to text being captured into a TextField?