Skip to content

Instantly share code, notes, and snippets.

@davidseek
Created February 8, 2021 03:16
Show Gist options
  • Save davidseek/22e40788419b2da1736ed03933e90948 to your computer and use it in GitHub Desktop.
Save davidseek/22e40788419b2da1736ed03933e90948 to your computer and use it in GitHub Desktop.
hotelWithAttributes.swift
// This is not a new Hotel class.
// It's the same class as above.
// I'm just not going to add every line of code to every snippet.
// This way it's easier for you to see,
// what lines of code I'm talking about.
class Hotel {
// We have 3 individual integers,
// that reflect the available rooms in total
let smallRoomsCount: Int
let mediumRoomsCount: Int
let largeRoomsCount: Int
// And we have 3 dictionaries that reference the rooms.
// 3 dictionaries, one each per size.
var smallRooms = [String: Dog]()
var mediumRooms = [String: Dog]()
var largeRooms = [String: Dog]()
// The custom intializer
init(small: Int, medium: Int, large: Int) {
smallRoomsCount = small
mediumRoomsCount = medium
largeRoomsCount = large
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment