Home>

We are developing an iOS app that allows you to select and view information on any date.

We adopted datePicker to select the date, and created a simple sample like the following image (I referred to here → https://www.tutorialfor.com/go.php?id=65426 )

Tap "Button" to go to the date selection screen. Select any date and then tap "done" to display the selected date in "Label" on the original screen.

After linking the Label from the storyboard to the ViewController, I tried to execute it, but the error Thread 1: signal SIGABRT occurred. It seems to be an error that occurs when deleting the link between storyboard and ViewController, but when I checked the link, "!" was attached to the connected Label, and there was "ViewController does not have an outlet named label".

I think there is no mistake in how to connect the storyboard to the ViewController, but for some reason a SIGABRT error occurs.

I would appreciate it if you could tell me the cause of this error and how to fix it. Also, please point out any points that are difficult to understand in the text.
Thank you.
* Almost the same as the reference source, but the code for this app is shown below.

FirstViewController.swift

import UIKit
class FirstViewController: UIViewController {

    @IBOutlet weak var label: UILabel!

    @IBAction func Done (segue: UIStoryboardSegue) {
        let secondVC = segue.source as! SecondViewController
        let datePicker = secondVC.datePicker
        let date = datePicker? .date
        let formatter = DateFormatter ()
        formatter.dateStyle = .medium
        formatter.timeStyle = .none
        formatter.dateFormat = "yyyyMMdd"
        let dateText = formatter.string (from: date!)
        label.text = dateText
    }
    override func viewDidLoad () {
        super.viewDidLoad ()
        // Do any additional setup after loading the view, typically from a nib.
    }
    override func didReceiveMemoryWarning () {
        super.didReceiveMemoryWarning ()
        // Dispose of any resources that can be recreated.
    }

}

SecondViewController.swift

import UIKit
class SecondViewController: UIViewController {
    @IBOutlet weak var datePicker: UIDatePicker!
    override func viewDidLoad () {
        super.viewDidLoad ()
        // Do any additional setup after loading the view.
    }
    override func didReceiveMemoryWarning () {
        super.didReceiveMemoryWarning ()
        // Dispose of any resources that can be recreated.
    }
}