Skip to content

Instantly share code, notes, and snippets.

@casademora
Created October 28, 2016 03:39
Show Gist options
  • Save casademora/9581611f69a59a511992389658c59e00 to your computer and use it in GitHub Desktop.
Save casademora/9581611f69a59a511992389658c59e00 to your computer and use it in GitHub Desktop.
Dynamic Swift Demo Source
//: 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