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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -