Last active
November 14, 2019 00:33
-
-
Save GeRryCh/ea47b448cd867614d30bc319c52a4a33 to your computer and use it in GitHub Desktop.
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
// | |
// 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