Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
Binary file modified
BIN
+964 Bytes
(110%)
...ground/playground.xcworkspace/xcuserdata/tibor.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Cocoa | ||
|
||
// Your challenge is this: 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 cost: Int { get set } | ||
var agent: String { get set } | ||
|
||
func salesSummary() | ||
} | ||
|
||
|
||
struct House: Building { | ||
let numberOfRooms: Int | ||
var cost: Int | ||
var agent: String | ||
|
||
func salesSummary() { | ||
print("This is a house.") | ||
print("It has \( self.numberOfRooms ) bedrooms.") | ||
print("You can buy it from \( agent ) for $\( cost )") | ||
} | ||
} | ||
|
||
|
||
struct Office: Building { | ||
let numberOfRooms: Int | ||
var cost: Int | ||
var agent: String | ||
|
||
func salesSummary() { | ||
print("This is an office building.") | ||
print("It has an open floor plan with space for \( self.numberOfRooms ) offices.") | ||
print("Contact \( agent ) for pricing details.") | ||
} | ||
} | ||
|
||
|
||
|
||
let home = House(numberOfRooms: 3, cost: 800_000, agent: "BayView Realtors") | ||
home.salesSummary() | ||
|
||
print() | ||
|
||
let loft = Office(numberOfRooms: 20, cost: 8_000_000, agent: "Enterprise Sales") | ||
loft.salesSummary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
checkpoint-8.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+13.8 KB
...ground/playground.xcworkspace/xcuserdata/tibor.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import Cocoa | ||
|
||
protocol Vehicle { | ||
func estimateTime(for distance: Int) -> Int | ||
func travel(distance: Int) | ||
} | ||
|
||
struct Car: Vehicle { | ||
func estimateTime(for distance: Int) -> Int { | ||
distance / 50 | ||
} | ||
|
||
func travel(distance: Int) { | ||
print("I'm driving \(distance)km.") | ||
} | ||
|
||
func openSunroof() { | ||
print("It's a nice day!") | ||
} | ||
} | ||
|
||
|
||
let twopointzero = 2.0 | ||
let two = 2 | ||
twopointzero == twopointzero | ||
two == two | ||
// This does not work, because of the different types. | ||
//two == twopointzero | ||
|
||
|
||
func trim(_ string: String) -> String { | ||
return string.trimmingCharacters(in: .whitespacesAndNewlines) | ||
} | ||
|
||
extension String { | ||
func trimmed() -> String { | ||
return self.trimmingCharacters(in: .whitespacesAndNewlines) | ||
} | ||
|
||
mutating func trim() -> Void { | ||
self = self.trimmed() | ||
} | ||
} | ||
|
||
let quote = " There is whitespace around. " | ||
|
||
quote.trimmed() | ||
quote | ||
|
||
var otherQuote = " There is also whitespace here " | ||
otherQuote.trim() | ||
otherQuote | ||
|
||
|
||
protocol SuperHeroMovie { | ||
func writeScript() -> String | ||
} | ||
extension SuperHeroMovie { | ||
func makeScript() -> String { | ||
return """ | ||
Lots of special effects, | ||
some half-baked jokes, | ||
and a hint of another | ||
sequel at the end. | ||
""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
day-13.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+13.7 KB
...ground/playground.xcworkspace/xcuserdata/tibor.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.