Created
November 3, 2017 03:19
-
-
Save lawreyios/30a25a1969bf938fde97664a491ad97e 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
//: Playground - noun: a place where people can play | |
import UIKit | |
class Developer { | |
var name: String? | |
init(name: String) { | |
self.name = name | |
} | |
} | |
protocol DevelopableInSwift { } | |
protocol DevelopableInKotlin { } | |
class iOSDeveloper:Developer, DevelopableInSwift { } | |
class AndroidDeveloper:Developer, DevelopableInKotlin { } | |
extension DevelopableInSwift where Self: iOSDeveloper { | |
func useGuard() { } | |
} | |
extension DevelopableInKotlin where Self: AndroidDeveloper { | |
func isNullSafe() -> Bool { return true } | |
} | |
class ViewController: UIViewController { | |
var developer: Developer { return AndroidDeveloper(name: "Lawrey") } | |
override func viewDidLoad() { | |
if developer is DevelopableInSwift, | |
let iOSDev = developer as? iOSDeveloper { | |
print("I am an iOS Developer!") | |
iOSDev.useGuard() | |
}else if developer is DevelopableInKotlin, | |
let androidDev = developer as? AndroidDeveloper { | |
print("I am an Android Developer!") | |
androidDev.isNullSafe() | |
} | |
} | |
} | |
let viewController = ViewController() | |
viewController.viewDidLoad() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment