I am new to Swift and trying to add a string
to an array in the previous viewController
. In my main view controller I have this method to declare the viewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var newSoundViewController = segue.destinationViewController as! NewSoundViewController
newSoundViewController.previousViewController = self
}
In the NewSoundViewController
, I have a method that adds a string
to the array of the previous viewController
. Here is that code:
@IBAction func saveTapped(sender: AnyObject) {
var sound = Sound()
sound.name = soundTextField.text
self.previousViewController.sounds.append(sound)
self.dismissViewControllerAnimated(true, completion: nil)
}