Post

Replies

Boosts

Views

Activity

Iterate over an array and delete events that is older than present's day.
Hi! I have an array with some parties information like date/place/day and time of the event in an array called events(eventos portuguese) and I want to iterate throught this array and check if the data of the event has passed today's date. This is the code I am using but for some reason that I don't know the forEach is not working: func checkEventsDate() { let dateFormatter = DateFormatter() self.eventos.forEach { item in guard let dt = dateFormatter.date(from: item.data) else { return } if dt > Date() { let index = self.eventos.firstIndex(of: item) self.eventos.remove(at: index!) } else { print("maior") } } } what am I missing or what am I doing wrong? I dont get any error messages just the code doesnt work. thank you very much
2
0
309
Nov ’23