Created
October 4, 2016 14:33
-
-
Save PaulTaykalo/5b72a197be0e9c63236677a3f4a20e9b to your computer and use it in GitHub Desktop.
Function Injection example
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 Foundation | |
import UIKit | |
class ImageProcessor { | |
let postProcessOp:(UIImage) -> () | |
init(postProcessOp:@escaping (UIImage) -> () = {_ in }) { | |
self.postProcessOp = postProcessOp | |
} | |
func processImage(original: UIImage) -> UIImage { | |
let image = original.imageFlippedForRightToLeftLayoutDirection() | |
postProcessOp(image) | |
return image | |
} | |
} | |
class Factory { | |
func validImageProcessor() -> ImageProcessor { | |
return ImageProcessor(postProcessOp: Cacher.saveCachedImage) | |
} | |
} | |
class Cacher { | |
static func saveCachedImage(image:UIImage) { | |
print("Feeling sick today - Won't cache anything") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment