How to modify the value of key from struct that is under nested of array of struct. I found one of possible solution from stackoverflow but it is only for one level. I am wondering if there is any better solution? and what if the key is optional?
struct Article {
var id: Int
var book: [Book]
}
struct Book {
var page: Int
var author: [Author]
}
struct Author {
var visited: Bool
}
// update value of visited key in nested array of struct
var a = Article(id: 1, book: [Book(page: 11, author: [Author(visited: true)])])
print(a)
a.book.modifyElement(atIndex: 0) {$0.author.modifyElement( atIndex: 0) {$0.visited = false}}
print(a)