0

I'm new to coding and this is my first app. Thanks in advance for the help.

The code is only saving today's date.

How do I save the selected date?

Here's my code:

import UIKit
import FSCalendar
import RealmSwift

class testViewController: UIViewController, FSCalendarDelegate, FSCalendarDataSource {
    
    @IBOutlet weak var calendar: FSCalendar!
    
    let realm = try! Realm()
    
    var datePicked = Date()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        calendar.delegate = self
        calendar.dataSource = self
        
    }
    
    @IBAction func nextPressed(_ sender: UIButton) {
        
        let newTransaction = Transaction()
        
        newTransaction.transactionDate = datePicked
        
        try! realm.write {
            realm.add(newTransaction)
        }
    }
    
    func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
        
        datePicked = date
        
        print(datePicked)
        
    }
}
BriScoLeg
  • 105
  • 1
  • 9

1 Answers1

0

I figured it out. Apologies, the error was in the code for reading the data. This write code for Realm is correct. I said I was a newbie!

BriScoLeg
  • 105
  • 1
  • 9