GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Solved: Checkpoint 8

Forums > 100 Days of SwiftUI

Hey everyone, Here is my solution for Checkpoint 8 and as always I am open to any feedback you might have. Thanks! :)

protocol Building {
    var type: String { get set }
    var rooms: Int { get set }
    var cost: Int { get set }
    var realEstateAgent: String { get set }

    func salesSummary() -> Int
}

extension Building {
    func salesSummary() -> Int {
        let commision = cost / 10
        print("\(realEstateAgent) earned $\(commision) commision for selling \(type) for $\(cost).")
        return commision
    }
}

struct House: Building {
    var type = String()
    var rooms = Int()
    var cost = Int()
    var realEstateAgent = String()
}

struct Office: Building {
    var type = String()
    var rooms = Int()
    var cost = Int()
    var realEstateAgent = String()
}

let house = House(type: "house", rooms: 5, cost: 1_000_000, realEstateAgent: "Betty")
house.salesSummary()

let office = Office(type: "office building", rooms: 100, cost: 10_000_000, realEstateAgent: "Bob")
office.salesSummary()

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.