Skip to content

Instantly share code, notes, and snippets.

@Viniciuscarvalho
Created August 22, 2018 14:34
Show Gist options
  • Select an option

  • Save Viniciuscarvalho/939834fd1c9f6c22556bd837fa446ac6 to your computer and use it in GitHub Desktop.

Select an option

Save Viniciuscarvalho/939834fd1c9f6c22556bd837fa446ac6 to your computer and use it in GitHub Desktop.
Extensão de reduce para unir elementos de um array de objeto e apresenta-los concatenados em lista.
extension Array where Iterator.Element == ObjectoDoModelo {
func presentableNames() -> String {
return self.compactMap({ $0.elementoDoObjeto })
.reduce("", { $0 + "\n" + $1 }).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment