Created
February 11, 2016 13:57
-
-
Save Gernot/84de90996f56763c3c56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])' |
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
Basically I want to store whatever is handled by the
doStuff()
function in a variable. I don't now the type beforehand. So anything generic would be cool, or[Any]
, which I can't seem to cast to whatever I need here though.