I have the following protocol
public protocol NumericType {
static func +(lhs: Self, rhs: Self) -> Self
static func addWithOverflow(_ lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
}
extension Int : NumericType { }
struct State<T:NumericType> {
let current : T
init(current : T) {
self.current = current
}
static func initial() -> State<T> {
return State(current: 0) // Int is not convertible to T
}
}
NumericType
does not promise that it is ExpressibleByIntegerLiteral
, so there's no way to convert 0
(which is assumed to be an Int
here) to T
. Your protocol needs to provide some .zero
that it knows it can initialize with (or it needs to conform to ExpressibleByIntegerLiteral
).