I have tried a lot of things with no luck on getting this working. The two date vars won't take my date. I think I need to do something with dateformatter but haven't found the right way yet. Can anyone shed some light on this?
struct CCdata {
var id: Int
var org_nm: String
var org_cd: String
var tms: String
var tec: String
var serno: String
var mcn: String
var jcn: String
var rcvd_dt: Date
var cmp_dt: Date
}
var firstTry = CCdata(id: 45, org_nm: "HSM73", org_cd: "Q30", tms: "MH-60R",
tec: "AHZS", serno: "167043", mcn: "1V4YSQU", jcn: "Q30113239",
rcvd_dt: 4/23/2018 0:00:00, cmp_dt: 5/2/2018 0:00:00)
Not sure to understand your question.
Yes, you can have a date in struc.
But the parameter when you create the instance of strcut must me a Date.
Such as, if you want to use present date:
var firstTry = CCdata(id: 45, org_nm: "HSM73", org_cd: "Q30", tms: "MH-60R",
tec: "AHZS", serno: "167043", mcn: "1V4YSQU", jcn: "Q30113239",
rcvd_dt: Date(),
cmp_dt: Date())
Now, if you want to specifiy your own date, you should create a Date as you specify
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy"
let cmp_dt = formatter.date(from: "5/2/2018 0:00:00") ?? Date() // This is a Date ; note that you must unwrap because formatter may fail
var firstTry = CCdata(id: 45, org_nm: "HSM73", org_cd: "Q30", tms: "MH-60R",
tec: "AHZS", serno: "167043", mcn: "1V4YSQU", jcn: "Q30113239",
rcvd_dt: Date(),
cmp_dt: cmp_dt)