Skip to content

Instantly share code, notes, and snippets.

@freesia
Created November 20, 2014 14:02
Show Gist options
  • Save freesia/c13510002890cdb23160 to your computer and use it in GitHub Desktop.
Save freesia/c13510002890cdb23160 to your computer and use it in GitHub Desktop.
Unique elements in swift array
func distinct<T: Equatable>( source: [T] ) -> [T]
{
var unique = [T]()
for item in source
{
if !contains( unique, item ) {
unique.append( item )
}
}
return unique
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment