Home > OS >  How can I have Hashable element type for an Array that is wrapped value for optional
How can I have Hashable element type for an Array that is wrapped value for optional

Time:05-05

I am looking the correct syntax of this code:

extension Optional where Wrapped == Array<Element> where Element == Hashable {

}

The elements of Array are Hashable.

CodePudding user response:

You can either constrain every member, or use a typealias. But you can't use properties unless you use the typealias solution.

typealias OptionalHashableArray<Hashable: Swift.Hashable> = [Hashable]?

extension OptionalHashableArray {
  var            
  • Related