Passing values from a custom view to Main View Controller - Swift
<p>I am working on a basic alarm app. This is how the main storyboard looks like</p>

<p><a href="https://i.stack.imgur.com/OwL0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OwL0o.png" alt="enter image description here"></a></p>

<p>I have added a custom view controller as a separate xib file which looks like this</p>

<p><a href="https://i.stack.imgur.com/cWy4u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cWy4u.png" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/pl0hx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pl0hx.png" alt="enter image description here"></a></p>

<p>And this is how the interface looks like when it runs. (The main ViewController in background and the CustomAlertController in the foreground)</p>

<p><a href="https://i.stack.imgur.com/h4En0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h4En0.png" alt="enter image description here"></a></p>

<p>It contains a date picker. What I mean to do is that when a user clicks on the addButton in the Main story board the customAlertViewController will come up and the user can choose a date and time to add as an alarm. When the user taps on Add in the customAlertViewController the date and time are supposed to be passed back into an array and added to the tableView in the Main storyboard view controller.</p>

<p>This is the code I have written so far:</p>

<p>Code for <strong>TableView</strong></p>

<pre><code>    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let cell = UITableViewCell()
    let adate = alarmDate[indexPath.row].date
    print(adate)
    cell.textLabel?.text = String(adate)
    return cell
    }
</code></pre>

<p>Code in the <strong>Alarm class</strong></p>

<pre><code>import Foundation
class Alarm{
    var date : NSDate
    init (date : NSDate){
        self.date = date
    }
}
</code></pre>

<p>Code in <strong>CustomAlertViewController</strong></p>

<p>You don't have to go through the entire code. I have tried using prepare for segue, but I guess that's not a doable solution when the CustomAlertviewcontroller is in a different storyboard(?)</p>

<p>The next approach I took was to somehow pass the date to an instance of Alarm class in the viewDidDisappear method, and subsequently append it to alarmDate array (declared in ViewController). </p>

<p>This is where I am getting stuck. The print statement in the viewDidDisappear outputs 1 to the console, obviously because the date has been appended. But once the CustomAlertViewController exits and the viewController is back, the alarmDate array resets and no value shows up in the table view. I have tried to work around this but to no avail.</p>

<p>I realise that if I had used a new view controller in the storyboard in place of a separate xib file, I could have achieved the same result easily.</p>

<pre><code>class CustomAlertViewController: UIViewController {
    //MARK: - Properties
    @IBOutlet weak var customAlertView: UIView!    
    @IBOutlet weak var alarmPicker: UIDatePicker!
    var destinationDate = NSDate()
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName : nibNameOrNil, bundle : nibBundleOrNil)
        self.modalPresentationStyle = .OverCurrentContext
    }
    convenience init(){
        self.init(nibName : "CustomAlertViewController", bundle: nil)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("NSCoding not supported")
    }


    //MARK: - Methods
    override func viewDidLoad() {
        super.viewDidLoad()
        print ("View loaded")
        self.customAlertView.layer.borderColor = UIColor.darkGrayColor().CGColor
        self.customAlertView.layer.borderWidth = 2
        self.customAlertView.layer.cornerRadius = 8
        view.backgroundColor = UIColor(white: 1, alpha: 0.7)
        view.opaque = false
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    override func viewDidDisappear(animated: Bool) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("table") as! ViewController
        let alarm = Alarm( date : destinationDate)
        vc.alarmDate.append(alarm)
//        vc.alarmData.reloadData()
        print(vc.alarmDate.count)
    }
    // MARK: - Navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let destinationVC = segue.destinationViewController as! ViewController
        let alarm = Alarm( date : destinationDate)
        destinationVC.alarmDate.append(alarm)
        destinationVC.alarmData.reloadData()
        print(destinationVC.alarmDate.count)
    }
    //MARK: - Actions
    @IBAction func cancelButton(sender: AnyObject) {
        self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil)
    }
    @IBAction func addButton(sender: AnyObject) {
        //Code to correct the time zone difference
        let sourceDate = alarmPicker.date
        let sourceTmeZone = NSTimeZone(abbreviation: "GMT")
        let destinationTimeZone = NSTimeZone.systemTimeZone()
        let sourceOffset = sourceTmeZone!.secondsFromGMTForDate(sourceDate)
        let destinationOffset = destinationTimeZone.secondsFromGMTForDate(sourceDate)
        let interval : Double
        interval = Double(destinationOffset - sourceOffset)
        destinationDate = NSDate.init(timeInterval: interval, sinceDate: sourceDate)

        self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil)
    }
}
</code></pre>

<p>I lack experience with Swift and would gladly appreciate any help.
PS I'm using Swift 2.3</p>