title: UIPickerView won't display the data loaded from NSUserDefaults - App is crashing while loading data
body: <p><em>I made a first try to use NSUserDefaults in an App with UIPickerViews. But the App is crashing while testing / the data isn't displayed in the PickerView. I still try to fix it myself but some help would be great.</em></p>
  
  <p><strong>ViewController3:</strong>
  <em>Where the user should save data to the NSUserDefault. Therefore there is an textField to write down something and a "Savebutton"</em> </p>
  
  <pre><code>class ViewController3: UIViewController, UITextFieldDelegate {
  
  @IBOutlet weak var textField: UITextField!
  </code></pre>
  
  <p>...</p>
  
  <pre><code> @IBAction func tappedAddButton(sender: AnyObject) {
  
      var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults()
  
      var exercisesList:NSMutableArray? = userDefaults.objectForKey("exercisesList") as? NSMutableArray
  
      var dataSet:NSMutableDictionary = NSMutableDictionary()
      dataSet.setObject(textField.text, forKey: "exercises")
  
      if ((exercisesList) != nil){
          var newMutableList:NSMutableArray = NSMutableArray();
  
          for dict:AnyObject in exercisesList!{
              newMutableList.addObject(dict as NSDictionary)
          }
  
          userDefaults.removeObjectForKey("exercisesList")
          newMutableList.addObject(dataSet)
          userDefaults.setObject(newMutableList, forKey: "exercisesList")
  
      }else{
          userDefaults.removeObjectForKey("exercisesList")
          exercisesList = NSMutableArray()
          exercisesList!.addObject(dataSet)
          userDefaults.setObject(exercisesList, forKey: "exercisesList")
      }
  
      userDefaults.synchronize()
  
      self.view.endEditing(true)
      textField.text = ""
  
  }
  </code></pre>
  
  <p><strong>ViewController 1:</strong>
  <em>Where the saved data should be loaded from NSUserDefaults and displayed in pickerView1</em></p>
  
  <pre><code>class ViewController: UIViewController,UIPickerViewDelegate {
  
  @IBOutlet weak var pickerView1: UIPickerView!
  @IBOutlet weak var pickerView2: UIPickerView!
  @IBOutlet weak var pickerView3: UIPickerView!
  
  var reps = [["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"],["x"]]
  
  var weight = [["0","1","2","3","4","5"],["0","1","2","3","4","5","6","7","8","9"],["0","1","2","3","4","5","6","7","8","9"],[","],["0","25","5","75"],["kg","lbs"]]
  
  var exercises:NSMutableArray = NSMutableArray();
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults()
  
      var exercisesListFromUserDefaults:NSMutableArray? = userDefaults.objectForKey("exercisesList") as? NSMutableArray
  
      if ((exercisesListFromUserDefaults) != nil){
          exercises = exercisesListFromUserDefaults!
      }
      self.pickerView1.reloadAllComponents()
  }
  
  func numberOfComponentsInPickerView(pickerView: UIPickerView) -&gt; Int {
  
      switch pickerView {
      case pickerView1:
          return 1
      case pickerView2:
          return reps.count
      case pickerView3:
          return weight.count
      default:
          assertionFailure("Unknown pickerView")
      }
  }
  
  func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
      switch pickerView {
      case pickerView1:
          return exercises.count
      case pickerView2:
          return reps[component].count
      case pickerView3:
          return weight[component].count
      default:
          assertionFailure("Unknown pickerView")
      }
  }
  
  func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String! {
      switch pickerView {
      case pickerView1:
          return exercises[row] as String
      case pickerView2:
          return reps[component][row]
      case pickerView3:
          return weight[component][row]
      default:
          assertionFailure("Unknown pickerView")
      }
  }
  
  }
  </code></pre>