Travis Whitten Travis Whitten - 1 year ago 120
Swift Question

Swift String Array Iterating Function

I am trying input an array with all the months and display them one by one on my scrollable calendar. I am trying to return each individual "month" for each header of the calendar.

I am using the following string array, yet i am unsure how to return a type of "String" for what i desire. Any ideas on what i am doing wrong? Thanks

let months: [String] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

func monthCounter(inputArray:Array<String>) -> String{
for name in inputArray{
return name



I am wanting to call this function to display each "month" string individually.

func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) {

let headerCell = (header as? MonthsHeader)
headerCell?.monthsHeader.text = monthCounter(inputArray: months)

Answer Source

There are serveral problems with your code. First of all, Array<String> should be [String] and returning from inside an iteration will terminate the iteration. You can call a function there, or you can print("\(name)") for a start.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download