Skip to content

Instantly share code, notes, and snippets.

View agoiabel's full-sized avatar

Agoi Abel Adeyemi agoiabel

View GitHub Profile
let name = "world"
if name == "world" {
print("hello, world")
} else {
print("I'm sorry \(name), dont know you")
}
let name = "world"
(name == "world") ? print("hello, world") : print("I'm sorry \(name), dont know you")
protocol FullNameable {
var fullName: String { get }
}
//First Implementation
struct Lecturer: FullNameable {
var fullName: String
}
let lecturer = Lecturer(fullName: "Gift")
//Second Implementation
struct Student: FullNameable {
let firstName: String
//First Implementation
struct Lecturer: FullNameable {
var fullName: String
}
let lecturer = Lecturer(fullName: "Gift")
lecturer.fullName //will return Gift
lecturer.fullName = "Abel" //This will fail
protocol Blendable {
func blend() -> ()
}
class Fruit: Blendable {
var name: String
init(name: String) {
self.name = name
}
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")
class Airplane {
let landingGear: String
func fly() {
print("I can fly")
}
}
class JetPlane: Airplane {
let jetEngine: String
protocol Flyable {
func fly() -> String
}
class Airplane: Flyable {
func fly() -> String {
return ("Airplane can fly")
}
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