0

My first array is for English words and my second array contains Spanish words. When the user enters a word in English from array1 the output will be the IndexOf array2. Instead of displaying the IndexOf array2 "1" how can I print the String in array 2.For example, I enter the word "cat" in the text field and click on "translate button" it will print out "0" index of array2. How can I print the word "gato" instead of 0?

var array1: [String]  = ["cat", "dog", "lion"]
var array2: [String]  = ["gato", "perro", "lion"]

for transIndex in array1.indices {
        if array1[transIndex] == emptyString!.lowercaseString {

            translatedWord.text = "\(transIndex)"

            //print("transIndex is \(array1)")
            return   

        }     
    } 
3
  • 1
    Change to translatedWord.text = "\(array2[transIndex])" Commented Mar 6, 2016 at 13:25
  • Great! that worked many thanks Commented Mar 6, 2016 at 13:30
  • Hey, if you have time would you mind checking out my recent post. Still a bit stuck on this stackoverflow.com/questions/35800592/… Commented Mar 6, 2016 at 13:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.