When I compile the code I get the error Cannot assign to property: 'car' is immutable
Questions
Why do I get the error When I compile the code I get the error Cannot assign to property: 'car' is immutable
How can I fix it?
Code
@dynamicMemberLookup
struct Car {
var price = 1000
var engine: Engine
subscript <T>(dynamicMember keyPath: WritableKeyPath<Engine, T>) -> T {
engine[keyPath: keyPath]
}
}
struct Engine {
var cylinders: Int
var horsepower: Int
}
var engine = Engine(cylinders: 4, horsepower: 200)
var car = Car(engine: engine)
car.engine.cylinders = 6
car.cylinders = 6 //Error: Cannot assign to property: 'car' is immutable
I must admit that the error Cannot assign to property: 'car' is immutable is very confusing. car is mutable but the property cylinders isn't mutable instead. Do you mind filling an issue?