Created
November 4, 2019 04:03
-
-
Save fmo91/10553fd54a45288863efac958b68a10d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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