Regardless of the specific compile-time issue you’re having here, I must warn you about using fixed-format date strings with
DateFormatter
. This is unlikely to produce the results you want. To learn more about why, read QA1480
NSDateFormatter and Internet Dates.
In situations like this, where you want to configure a date formatter to work with a specific set of components, use
dateFormat(fromTemplate:options: locale:)
or the newer convenience method
setLocalizedDateFormatFromTemplate(_:)
. For example:
let df = DateFormatter()
df.setLocalizedDateFormatFromTemplate("dMMM")
let nowStr = df.string(from: Date())
print(nowStr)
prints
May 9
for US users and
9 May
for UK users.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"