Greetings
I have a generic Property class that takes a valueT parameter:
class Property<valueT : DefaultValueProvider>
{
var value: valueT = valueT() // from DefaultValueProvider
}
Now, I want to implement Copyable:
public protocol Copyable
{
init(other: Self)
}
public extension Copyable
{
public func copy() -> Self
{
return .init(other: self)
}
}
But, for that to work correctly, I also want the valueT to be able to cope with both value types and reference types, calling copy() on a value type instead of the default copying behaviour of value types.
So, I thought I would write an extension on Property to provide a "conditional" initialiser:
extension Property where valueT : Copyable
{
public convenience init(other: Property<valueT>)
{
self.init()
value = other.value.copy()
}
}
After spending a few hours juggling things around, this initialiser is still not getting called. Thus, changing any of the properties on the reference type changes in both the original and the copy.
Am I missing something blindingly obvious here ?