Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a String array of years like monthSymbols in Swift?

Tags:

arrays

ios

swift

I want to get an array of Strings years like monthSymbols.

example: [2017, 2018, 2019, 2020,... 2100]

I do that with the month of year:

let formatter = DateFormatter()
let monthComponents = formatter.monthSymbols

but I can't do the same with the years. any help?

like image 307
steibour Avatar asked Apr 27 '17 21:04

steibour


1 Answers

I don't think such a thing exists. An arbitrary list of years can't really be handled in the same way as a specific list of month names.

let years = (2017...2100).map { String($0) } is probably the cleanest way to do what you're looking for.

like image 152
John Montgomery Avatar answered Nov 15 '22 05:11

John Montgomery