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
Post a Comment