How to remove the values from the range in ViewController



  • ViewController has two fields and a button. The point is that the English word is in the 1st field (andomno) and the translation of the word is in the 2nd field. And a puncture for an early word generation.

    I created two sets of English words and Russians:

    var englishWord = ["Apartment", "Actor", "Arm", "Anger", "Ash", "Army", "Action", "Attitude", "Aisle", "After"]    
    var russianWord = ["Комната; Квартира", "Актер, Артист", "Рука", "Гнев", "Зола, Пепел; Прах", "Армия", "Поступок, Действие", "Позиция; Отношение к", "Проход", "prep- После, Через; adv- Потом"]
    

    Gheter and seter for field removal

    var english: String {
        get {
          return englishInput.text!
        }
        set{
          let englishvalue = "\(newValue)"
          englishInput.text = "\(newValue)"
        }
      }
    

    var russia: String {
    get {
    return russianInput.text!
    }
    set{
    let russiavalue = "(newValue)"
    russianInput.text = "(newValue)"
    }
    }

    If you write this:

     englishInput.text = String(arc4random_uniform(UInt32(englishWord.count)))

    Only elements of the mass are produced

    And if you write that:

    let engRandom = String(arc4random_uniform(UInt32(englishWord.count)))
    englishInput.text = [engRandom]

    He's making a mistake.


  • QA Engineer

    You generate a number, but you don't take an element from this index, and you pull that number.

    Must be:

    let index = Int(arc4random_uniform(UInt32(englishWord.count)))
    englishInput.text = englishWord[index]
    russianOutput.text = russianWord[index]
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2