CH. 4 - History View - Date Format issues

I am having trouble getting the date format to work.
Code in the book…
Form {
Section(
header:
Text(today.formatted(as: “MMM d”))
ERROR → Argument passed to call that takes no arguments.
.font(.headline)) {
// Section content
}

I have arrived at this version…
Form {
Section(
header:
Text(today.formatted(date: .abbreviated, time: .shortened))
.font(.headline)) {
// Section content
}

I am assuming something has changed in the current SwiftUI.
I copied and pasted the code from the Final Folder in the Downloaded code and same errors.

Xcode Version 13.1, macOS Monterey Version 12.0.1

EDIT → I worked out because I never use Starter Projects I failed to see a DateExtension.swift file.
I copied that code to my project and all works as expected…I like starting from scratch and hate the Starter Project approach.

3 Likes
  Form {
                Section(
                    header:
                        Text(today.formatted(.dateTime.day().month()))
                        .font(.headline)) {
                            // section content
                        }
                Section(
                    header:
                        Text(yesterday.formatted(.dateTime.day().month()))
                        .font(.headline)) {
                            // Section content
                        }
            }

I used to that way and have similar view

hi Abdullah, did you start with the starter project when you did chapter 2? it has a DateExtension file that defines formatted(as:).

1 Like

hi, I just realized that, and come here to change my reply and see your reply. I have started a project without any ill from sources that mean my project does not have DateExtension file. Thank you.

1 Like