Skip to content

Instantly share code, notes, and snippets.

@EvolvingParty
Created November 20, 2022 12:19
Show Gist options
  • Save EvolvingParty/eabb20fc24252b4b04bed7da05a9f2f0 to your computer and use it in GitHub Desktop.
Save EvolvingParty/eabb20fc24252b4b04bed7da05a9f2f0 to your computer and use it in GitHub Desktop.
DAY 13. 100 Days of SwiftUI – Hacking with Swift. Checkpoint 8
import Cocoa
///Make a protocol that describes a building, adding various properties and methods, then create two structs, House and Office, that conform to it. Your protocol should require the following:
///A property storing how many rooms it has.
///A property storing the cost as an integer (e.g. 500,000 for a building costing $500,000.)
///A property storing the name of the estate agent responsible for selling the building.
///A method for printing the sales summary of the building, describing what it is along with its other properties.
protocol Building {
var numberOfRooms: Int { get }
var bulidingPrice: Int { get set }
var realEstateAgent: String { get }
func getSalesSummary()
}
struct House: Building {
func getSalesSummary() {
print("This building is a House with \(numberOfRooms) rooms, listed at $\(bulidingPrice) by \(realEstateAgent)")
}
var numberOfRooms: Int
var bulidingPrice: Int
var realEstateAgent: String
}
struct Office: Building {
func getSalesSummary() {
print("This building is an Office with \(numberOfRooms) rooms, listed at $\(bulidingPrice) by \(realEstateAgent)")
}
var numberOfRooms: Int
var bulidingPrice: Int
var realEstateAgent: String
}
let house24GreenStreet = House(numberOfRooms: 4, bulidingPrice: 390_000, realEstateAgent: "Kendall Jenner")
let officeBlockNorth = Office(numberOfRooms: 12, bulidingPrice: 599_000, realEstateAgent: "Scott Disick")
house24GreenStreet.getSalesSummary()
officeBlockNorth.getSalesSummary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment