Hello everyone,
I'm trying to use the
function in my code. I've put it where functions usually go, but it expects me to return something. Basically, I don't know what to put
I might be really confusing how this function should be used. By the way, I'm calling this function like this:
I'm trying to use the
Code Block func isDateInToday(_ date: Date) -> Bool
function in my code. I've put it where functions usually go, but it expects me to return something. Basically, I don't know what to put
Code Block func isDateInToday(_ date: Date) -> Bool { // here }
I might be really confusing how this function should be used. By the way, I'm calling this function like this:
Code Block if isDateInToday(oneTimeDate) { Text("Today at \(oneTimeDate, formatter: itemFormatter)") }
Assume you want to call this isDateInToday(_:):Any thoughts?
(When you ask something about functions defined in a framework, you should better include a link to the doc of it.)
In this case, isDateInToday is an instance method. When you want to call an instance method of some other type, you need to prefix instanceName:
Code Block instanceName.isDateInToday(oneTimeDate)
The instance needs to be of type Calendar, you can get the instance of the user's current Calendar with Calendar.current:
Code Block struct OneTimeRow: View { let calendar = Calendar.current //<- An instance of `Calendar` //... var body: some View { //... if calendar.isDateInToday(oneTimeDate) { Text("Today at \(oneTimeDate, formatter: itemFormatter)") } else if calendar.isDateInYesterday(oneTimeDate) { //<- `isDateInYesterday`, not `isDateinYesterday` Text("Yesterday at \(oneTimeDate, formatter: itemFormatter)") } else if calendar.isDateInTomorrow(oneTimeDate) { Text("Tomorrow at \(oneTimeDate, formatter: itemFormatter)") } else { //... } //... } }