I have a books array of struct Book that I am looping through trying to find if one of the book's properties is equal to a specific predefined value, and then I'd like to rearrange the element
if books.contains(where: { $0.structProperty == value }) {
books.rearrange(from: $0, to: 1)
}
And this is the rearrange function declared in an array extension file
extension Array {
mutating func rearrange(from: Int, to: Int) {
insert(remove(at: from), at: to)
}
}
With this setup I am getting this compile error:
Anonymous closure argument not contained in a closure
How can I go about achieving it without relying on a for loop?