I Have this struct
struct Friend: Identifiable {
var name: String
let bday: Date
let id = UUID()
}
and this code:
struct FriendView: View {
@Binding var friends: [Friend]
var dateFormatter: DateFormatter { ... }
var body: some View {
VStack {
List {
ForEach(friends) { friend in
HStack {
Text(friend.name)
Spacer()
Text(self.dateFormatter.string(from: friend.bday))
}
}
}
}
}
How to sort birthdays in swiftUI so that next birthday from today is on top of the list?
I have tried putting friends.sorted(by: {$0.bday < $1.bday}) in if statement but then i just get the oldest friend on top, and not the next one who has a birthday this year. I would appreciate any help very much.
Thank you in advance!
Selecting any option will automatically load the page