Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created November 4, 2019 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmo91/10553fd54a45288863efac958b68a10d to your computer and use it in GitHub Desktop.
Save fmo91/10553fd54a45288863efac958b68a10d to your computer and use it in GitHub Desktop.
struct Person {
let name: String
}
struct People {
// This empty array will be the wrappedValue in the init.
@Sorted(by: { $0.name < $1.name }) var items: [Person] = []
}
var people = People()
people.append(Person(name: "John"))
people.append(Person(name: "Harry"))
people.append(Person(name: "Allan"))
print(people.items.map({ $0.name })) // ["Allan", "Harry", "John"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment