Skip to content

Instantly share code, notes, and snippets.

@flaviodsilverio
Last active November 14, 2023 15:45
Show Gist options
  • Save flaviodsilverio/b806d35f14c2e4e285790680a88f2ea9 to your computer and use it in GitHub Desktop.
Save flaviodsilverio/b806d35f14c2e4e285790680a88f2ea9 to your computer and use it in GitHub Desktop.
Mastering Arrays in Swift
var arrayToMaster = [7, 2, 10, 4, 5]
arrayToMaster.sort(by: <)
print(arrayToMaster)
arrayToMaster.sort { s1, s2 in
s1 > s2
}
print(arrayToMaster)
// Person class representing inhabitants of the house
class Person {
var firstName: String
var lastName: String
var age: Int
init(firstName: String, lastName: String, age: Int) {
self.firstName = firstName
self.lastName = lastName
self.age = age
}
}
// House struct with address, ID, and an array of inhabitants
struct House {
var address: String
var id: Int
var inhabitants: [Person]
init(address: String, id: Int, inhabitants: [Person]) {
self.address = address
self.id = id
self.inhabitants = inhabitants
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment