swift - indexOf(Element) doesn't exist for [Foo.Type] arrays -


swift's collectiontype provides 2 indexof methods: 1 takes element directly, , 1 takes predicate function. if have array of type [foo.type] (for class foo), former doesn't exist; there's predicate version of indexof. why this?

the indexof method takes element requires element must conform equatable protocol. it's defined in constrained protocol extension, shows when constraint holds true.

metatypes (of form sometype.type) cannot conform protocols (current of swift 2.1). therefore though can define == operator @ global scope operates on metatypes, can't have metatype conform equatable protocol. known language limitation.

in cases (e.g. when using types keys in dictionary) may able use standard library objectidentifier type work around limitation.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -