title: How can I pass UITextField string from SecondViewController to array in Model Class?
body: <p>I am creating a flash card app with a model and two view controllers. In the first scene I display the questions and answers, cycling through the arrays of questions and answers. The questions and answers arrays are stored in the Model class. The second scene/view controller's purpose is t be able to edit the questions and answers by editing the text in the <code>UITextField</code>s and after pressing the OK button, the questions and answers arrays are updated to the text in the TextFields. </p>
  
  <p>When editing the "question" and "answer" text fields in the Second ViewController, changes to those strings have to be applied to the same FlashCardModel object that is used in the First Scene.</p>
  
  <p>How do I update the questions array in the model class with the value of the questionTextField?</p>
  
  <pre><code>//  FlashCardModel.swift
  //  TabbedFlashCards
  //
  //
  //
  //
  
  import Foundation
  
  class FlashCardModel {
      var currentQuestionIndex = 0;
      var questions = ["What is 1*7?", "What is 2*7?", "What is 3*7?"]
      var answers = ["7", "14", "21"]
  
      init(){
          //Any useful Constructor code would go here
      }
  
      func getNextQuestion() -&gt; String{
          currentQuestionIndex = currentQuestionIndex + 1;
          if(currentQuestionIndex &gt;= questions.count){
              currentQuestionIndex = 0;
          }
          return questions[currentQuestionIndex]
      }
  
      func getAnswer() -&gt; String{
          return answers[currentQuestionIndex]
      }
  
      func getCurrentQuestion() -&gt; String{
          return questions[currentQuestionIndex]
      }
  
      func setCurrentQuestion(pString : String){
          questions[currentQuestionIndex] = pString
      }
  
      func setCurrentAnswer(pString : String){
          answers[currentQuestionIndex] = pString
      }
  }//End of model
  
  //
  //  SecondViewController.swift
  //  TabbedFlashCards
  //
  //
  
  import UIKit
  
  class SecondViewController: UIViewController {
      // the reference to our AppDelegate:
      var appDelegate: AppDelegate?
      // the reference to our data model:
      var myFlashCardModel: FlashCardModel?
  
      @IBOutlet weak var questionTextField: UITextField!
      @IBOutlet weak var answerTextField: UITextField!
  
      @IBAction func buttonOKAction(sender: AnyObject) {
          self.appDelegate = UIApplication.shared.delegate as? AppDelegate
          self.myFlashCardModel = self.appDelegate?.myFlashCardModel
  
          var text: String = questionTextField.text!
  
          //myFlashCardModel?.setCurrentQuestion(pString: editQuestion)
          //print ("self.questionTextField.text = \(self.questionTextField.text)")
          //print ("self.answerTextField.text = \(self.answerTextField.text)")
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.questionTextField.text = "Question"
          self.answerTextField.text = "Answer"
      }
  }
  </code></pre>