Вы используете неправильный метод.Это должно быть func firstIndex(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Index?
вместо func firstIndex(of element: Book) -> Int?
if let i = tempArray.firstIndex(where: { $0.title.contains("Some Title") }) {
tempArray.remove(at: i)
}
Другой вариант - использовать метод RangeReplaceableCollection
mutating func removeAll(where shouldBeRemoved: (Book) throws -> Bool) rethrows
:
tempArray.removeAll { $0.title.contains("Some Title") }
Тестирование игровой площадки:
struct Book: Codable, Equatable {
let category, title, author: String
}
var tempArray: [Book] = [.init(category: "", title: "Some Title", author: "")]
print(tempArray) // "[__lldb_expr_12.Book(category: "", title: "Some Title", author: "")]\n"
tempArray.removeAll { $0.title.contains("Some Title") }
print(tempArray) // "[]\n"