Skip to content

Instantly share code, notes, and snippets.

View SamStone92's full-sized avatar

Sam Stone SamStone92

  • Gloucester, UK
View GitHub Profile
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
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
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)
class Springboard {
private var openCommands = [Command]()
private var closeCommands = [Command]()
func setCommand(openCommand : Command, closeCommand : Command) {
self.openCommands.append(openCommand)
self.closeCommands.append(closeCommand)
}
class ClockAppCloseCommand : Command {
let clockApp : ClockApp
init(clockApp : ClockApp) {
self.clockApp = clockApp
}
func execute() {
self.clockApp.removeClock()
class WeatherAppCloseCommand : Command {
let weatherApp : WeatherApp
init(weatherApp : WeatherApp) {
self.weatherApp = weatherApp
}
func execute() {
self.weatherApp.deleteWeatherData()
class WeatherAppOpenCommand : Command {
let weatherApp : WeatherApp
init(weatherApp : WeatherApp) {
self.weatherApp = weatherApp
}
func execute() {
self.weatherApp.getWeatherData()
class ClockApp {
func showClock() {
print("Showing clock")
}
func removeClock(){
print("Removing clock")
}
protocol Command {
func execute()
}
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")