Daniel Chepenko Daniel Chepenko - 9 days ago 7
iOS Question

DataFormatterStyle has no member .mediumStyle

In closure I want to set styles for date and time,

private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .mediumStyle
formatter.timeStyle = .shortStyle
return formatter
}()


but getting such error

Type 'DataFormatterStyle has no member .mediumStyle'


Previously with NSDateFormatter worked fine

Answer

Look at the documentation for DateFormatter.Style. Your code should be:

private let dateFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateStyle = .medium
    formatter.timeStyle = .short
    return formatter
}()

Just about everything changed in Swift 3.