Closed junpluse closed 7 years ago
Extract the load methods (originally implemented as a protocol extension for [Image|Video]Loadable) as new [Image|Video]SceneLoader structs.
load
[Image|Video]Loadable
[Image|Video]SceneLoader
// old extension ImageLoadable where Self: SceneLoadable { public func load(_ image: UIImage, format: MediaFormat) { // create scene... self.scene = scene } } // new extension ImageLoadable where Self: SceneLoadable { public func load(_ image: UIImage, format: MediaFormat) { ImageSceneLoader(target: self).load(image, format: format) } } public struct ImageSceneLoader<Target: SceneLoadable>: ImageLoadable { public let target: Target public init(target: Target) { self.target = target } public func load(_ image: UIImage, format: MediaFormat) { // create scene... target.scene = scene } }
So now you can reuse the default implementation when you override them.
class MyViewController: SceneLoadable, ImageLoadable { var scene: SCNScene? func load(_ image: UIImage, format: MediaFormat) { ImageSceneLoader(target: self).load(image, format: format) // your custom logic... } }
Extract the
load
methods (originally implemented as a protocol extension for[Image|Video]Loadable
) as new[Image|Video]SceneLoader
structs.So now you can reuse the default implementation when you override them.