Skip to content

Instantly share code, notes, and snippets.

@GeRryCh
Last active November 14, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeRryCh/ea47b448cd867614d30bc319c52a4a33 to your computer and use it in GitHub Desktop.
Save GeRryCh/ea47b448cd867614d30bc319c52a4a33 to your computer and use it in GitHub Desktop.
//
// Created by German Velibekov on 11/11/2019.
// Copyright © 2019 german. All rights reserved.
//
import UIKit
protocol Fiance {}
protocol PoorGuy {}
class Person {}
class AnyPerson: Person {}
class Bride: Person, Fiance {}
class Groom: Person, PoorGuy {}
protocol Friendly {
func sayHi(to person: Person)
}
extension Friendly {
func sayHi(to person: Person) {
//fiance talks to poor guy
if let _ = self as? Fiance,
let _ = person as? PoorGuy {
print("Hey, German. Why so sad?")
}
//poor guy talks to fiance
else if let _ = self as? PoorGuy,
let _ = person as? Fiance {
print("Hi, Dana! I'm still using if-elses. That's why 😔")
}
else {
print("Hi")
}
}
}
extension Person: Friendly {}
let anyPerson = AnyPerson()
let happyBride = Bride()
let missingGroom = Groom()
missingGroom.sayHi(to: anyPerson)
happyBride.sayHi(to: anyPerson)
happyBride.sayHi(to: missingGroom)
missingGroom.sayHi(to: happyBride)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment