UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.