Date() as String and storage in array

Good morning to everyone, I have a trouble with storage of Date() format.

I wrote this code and I convert Date() as a string in a swift file with string array:

var dayOfRecord = Date() var dataOK: String { return DateFormatter.localizedString(from: dayOfRecord, dateStyle: .short, timeStyle: .none) }

In another swift file (AddView) I wrote this code: DatePicker("", selection: $dayOfRecord, displayedComponents: .date)

Now I have to store this information in an array of other strings but return an error: Cannot find '$dayOfRecord' in scope

Where is my error? Thanks!

Please format code with code formatter.

var dayOfRecord = Date()
var dataOK: String { return DateFormatter.localizedString(from: dayOfRecord, dateStyle: .short, timeStyle: .none) }

For the error,

DatePicker("", selection: $dayOfRecord, displayedComponents: .date)

Have you defined a State var in the View where you use the DatePicker ?

@State private var dayOfRecord = Date()
Date() as String and storage in array
 
 
Q