Created
October 28, 2016 03:39
-
-
Save casademora/9581611f69a59a511992389658c59e00 to your computer and use it in GitHub Desktop.
Dynamic Swift Demo Source
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 | |
public protocol Maths | |
{ | |
func doMath(left: Double, right: Double) -> Double | |
} | |
class Addition: NSObject, Maths | |
{ | |
func doMath(left: Double, right: Double) -> Double | |
{ | |
return left + right | |
} | |
} | |
class Multiplication: Maths | |
{ | |
let next: AnyObject = Addition() | |
override func forwardingTarget(for aSelector: Selector!) -> Any? | |
{ | |
// return Addition() | |
return next | |
} | |
func doMath(left: Double, right: Double) -> Double | |
{ | |
return left * right | |
} | |
} | |
let math: AnyObject = Multiplication() | |
//math.perform(Selector("doMath::"), with: 40, with: 2) | |
math.doMath(left: 2, right: 40) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment