Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A super simplified sample on a calendar view model which changes its values based on user's selection.
import Foundation
class CalendarViewModel {
var selectedCheckInDate: NSDate?
var selectedCheckOutDate: NSDate?
func update(selectedDate date: NSDate) {
switch (selectedCheckInDate, selectedCheckOutDate) {
case (.none, .none):
selectedCheckInDate = date
case (.some(_), .none):
selectedCheckOutDate = date
case (.some(_), .some(_)):
selectedCheckOutDate = nil
selectedCheckInDate = date
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment