I\'m using a computed property to get the last book in my books
array. However, it seems I can\'t use this property to directly set a book\'s position
The error occurs because you did not tell the compiler what to do if the value of currentBook
is mutated. The compiler assumes it is immutable.
Just add a setter so that the compiler knows what to do when you set the value:
var currentBook: Book {
get { return books[books.count - 1] }
set { books[books.count - 1] = newValue }
}
Or, consider using books.last!
:
books.last!.position = CGPoint.zero