This file contains hidden or 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
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { | |
let container = transitionContext.containerView | |
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else { return } | |
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else { return } | |
self.isPresenting ? container.addSubview(toView) : container.insertSubview(toView, belowSubview: fromView) | |
let detailView = isPresenting ? toView : fromView | |
This file contains hidden or 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
class CustomAnimator : NSObject, UIViewControllerAnimatedTransitioning { | |
var duration : TimeInterval | |
var isPresenting : Bool | |
var originFrame : CGRect | |
var image : UIImage | |
init(duration : TimeInterval, isPresenting : Bool, originFrame : CGRect, image : UIImage) { | |
self.duration = duration | |
self.isPresenting = isPresenting | |
self.originFrame = originFrame |
This file contains hidden or 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
let springboard = Springboard() | |
let weatherApp = WeatherApp() | |
let clockApp = ClockApp() | |
springboard.setCommand(openCommand: WeatherAppOpenCommand(weatherApp: weatherApp), closeCommand: WeatherAppCloseCommand(weatherApp: weatherApp)) | |
springboard.openApp(atIndex: 0) | |
springboard.closeApp(atIndex: 0) | |
springboard.setCommand(openCommand: ClockAppOpenCommand(clockApp: clockApp), closeCommand: ClockAppCloseCommand(clockApp: clockApp)) | |
springboard.openApp(atIndex: 1) |
This file contains hidden or 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
class Springboard { | |
private var openCommands = [Command]() | |
private var closeCommands = [Command]() | |
func setCommand(openCommand : Command, closeCommand : Command) { | |
self.openCommands.append(openCommand) | |
self.closeCommands.append(closeCommand) | |
} |
This file contains hidden or 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
class ClockAppCloseCommand : Command { | |
let clockApp : ClockApp | |
init(clockApp : ClockApp) { | |
self.clockApp = clockApp | |
} | |
func execute() { | |
self.clockApp.removeClock() |
This file contains hidden or 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
class WeatherAppCloseCommand : Command { | |
let weatherApp : WeatherApp | |
init(weatherApp : WeatherApp) { | |
self.weatherApp = weatherApp | |
} | |
func execute() { | |
self.weatherApp.deleteWeatherData() |
This file contains hidden or 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
class WeatherAppOpenCommand : Command { | |
let weatherApp : WeatherApp | |
init(weatherApp : WeatherApp) { | |
self.weatherApp = weatherApp | |
} | |
func execute() { | |
self.weatherApp.getWeatherData() |
This file contains hidden or 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
class ClockApp { | |
func showClock() { | |
print("Showing clock") | |
} | |
func removeClock(){ | |
print("Removing clock") | |
} | |
This file contains hidden or 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
protocol Command { | |
func execute() | |
} |
This file contains hidden or 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
var macbookRegular: MacBook = MacBookRegular() | |
print("Cost : £\(macbookRegular.cost), Description: \(macbookRegular.description)") | |
macbookRegular = ProcessorUpgrade(macbook: macbookRegular) | |
print("Cost : £\(macbookRegular.cost), Description: \(macbookRegular.description)") | |
macbookRegular = SSDUpgrade(macbook: macbookRegular) | |
print("Cost : £\(macbookRegular.cost), Description: \(macbookRegular.description)") | |
macbookRegular = TouchBarUpgrade(macbook: macbookRegular) | |
print("Cost : £\(macbookRegular.cost), Description: \(macbookRegular.description)\n") |