Instantly share code, notes, and snippets.

Embed
What would you like to do?
public func reportToList(_ stations: [StationRecord]) -> String?
{
guard let mainTemplate = self.loadTemplate(ofType: .list),
let rowTemplate = self.loadTemplate(ofType: .listRow)
else
{
return nil
}
let rows = stations
.map({
var ocuppation_style = ""
switch $0.occupation
{
case .low:
ocuppation_style = "low-occupation"
case .medium:
ocuppation_style = "middle-occupation"
case .high:
ocuppation_style = "high-occupation"
case .unavailable:
ocuppation_style = "offline-occupation"
}
let row = String(format: rowTemplate, ocuppation_style, "\($0.name)", "\($0.bikes)", "\($0.docks)")
return row
})
.reduce("") { $0 + $1 }
let content = String(format: mainTemplate, rows)
return content
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment