This file contains hidden or 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
let name = "world" | |
if name == "world" { | |
print("hello, world") | |
} else { | |
print("I'm sorry \(name), dont know you") | |
} |
This file contains hidden or 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
let name = "world" | |
(name == "world") ? print("hello, world") : print("I'm sorry \(name), dont know you") |
This file contains hidden or 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
protocol FullNameable { | |
var fullName: String { get } | |
} |
This file contains hidden or 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
//First Implementation | |
struct Lecturer: FullNameable { | |
var fullName: String | |
} | |
let lecturer = Lecturer(fullName: "Gift") | |
//Second Implementation | |
struct Student: FullNameable { | |
let firstName: String |
This file contains hidden or 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
//First Implementation | |
struct Lecturer: FullNameable { | |
var fullName: String | |
} | |
let lecturer = Lecturer(fullName: "Gift") | |
lecturer.fullName //will return Gift | |
lecturer.fullName = "Abel" //This will fail |
This file contains hidden or 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
protocol Blendable { | |
func blend() -> () | |
} | |
class Fruit: Blendable { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} |
This file contains hidden or 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
func makeSmoothie(with ingredients: [Blendable]) { | |
for ingredient in ingredients { | |
ingredient.blend() | |
} | |
} | |
let orange = Fruit(name: "Orange") | |
let strawberry = Fruit(name: "Strawberry") | |
let chocolateMilk = Milk(name: "Chocolote") |
This file contains hidden or 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
class Airplane { | |
let landingGear: String | |
func fly() { | |
print("I can fly") | |
} | |
} | |
class JetPlane: Airplane { | |
let jetEngine: String |
This file contains hidden or 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
protocol Flyable { | |
func fly() -> String | |
} | |
class Airplane: Flyable { | |
func fly() -> String { | |
return ("Airplane can fly") | |
} | |
This file contains hidden or 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
protocol Animal { | |
var noOfLegs: Int | |
} | |
protocol Pet: Animal { | |
var name: String | |
} | |
class Dog: Pet { | |
//we must have the var name & noOfLegs in the Dog class |