Skip to content

Instantly share code, notes, and snippets.

@Gernot
Created February 11, 2016 13:57
Show Gist options
  • Save Gernot/84de90996f56763c3c56 to your computer and use it in GitHub Desktop.
Save Gernot/84de90996f56763c3c56 to your computer and use it in GitHub Desktop.
import Foundation
func doStuff<T:CollectionType where T.Generator.Element: Equatable, T.Index.Distance == Int>(collection:T) {
//Do Stuff
}
var list: [Any] = [1,2,2,3,4,5] //This HAS to be saved as [Any]. Or is there another way to specify all kinds of collections that would work with doStuff()?
doStuff(list) //This fails: cannot invoke 'doStuff' with an argument list of type '([Any])'
@smic
Copy link

smic commented Feb 11, 2016

You can use a custom protocol like
protocol MyEquatable {
func isEqual(object: Any) -> Bool
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment