I am trying to initialise a empty dictionary with custom type in Swift but I am getting '>' is not a postfix unary operator error
struct Prims {
var msSet = [Vertex<Int> : Double]() // This lines gives error
}
I tried another way; still getting same error
struct Prims {
var msSet: [Vertex<Int> : Double]
init() {
self.msSet = [Vertex<Int> : Double]()
}
}
I have defined Vertex in separate file
import Foundation
public struct Vertex<T: Hashable> {
var data: T
}
extension Vertex: Hashable {
public var hashValue: Int {
return "\(data)".hashValue
}
static public func ==(lhs: Vertex, rhs: Vertex) -> Bool {
return lhs.data == rhs.data
}
}
extension Vertex: CustomStringConvertible {
public var description: String {
return "\(data)"
}
}
I am looking for Why
it is happening. I know using var msSet = Dictionary<Vertex<Int>, Double>()
will work.