public extension Array where Element:SpaceCoordinateProtocol {
subscript <A:SpaceAxisProtocol>(_ axis:A) -> Element? where A == Element.Axis
{
get {
return self.first(where: {$0.axis == axis})
}
set {
if let coordinate = newValue,
let index = self.firstIndex(where: {$0.axis == coordinate.axis })
{
self[index].at = coordinate.at
}
}
}
}
When I get value, it works OK,
var l = axes[bold].at
But if I try to set value:
axes[bold].at = 3.6
I have compiler error Cannot convert value of type 'Axis' to expected argument type 'Int'
Is this behaviour expected? Is it possible to use axis[bold].at = something?
bold isn't an Int, and that it implements SpaceAxisProtocol
at is a property on SpaceCoordinateProtocol
You didn't add at property on Optional
then var l = axes[bold].at shouldn't work even though you say it works. axes[bold] is an Optional<Element>, which doesn't have a at property. Did you forget to write a question mark? Is any of my assumptions wrong?