the Reverend
the Reverend

Reputation: 12549

Extending Array only when the element type is of a specific type

I want to extend the array type only when its elements is of a specific type. In this case I'm using instances of EKCalendar.

This does not work:

public extension Array where Generator.Element : EKCalendar{

}

But this Does:

public extension CollectionType where Generator.Element : EKCalendar{

}

Why is it I can only do this with a protocol ?

Upvotes: 1

Views: 94

Answers (1)

Marco Boschi
Marco Boschi

Reputation: 2333

While extending Array you cannot access Generator.Element because it's part of the CollectionType protocol, you need to use Element:

public extension Array where Element: EKCalendar {
   //....
}

Upvotes: 3

Related Questions