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
private var series: [AXDataSeriesDescriptor] { | |
// 1 | |
let yValuesSeries1 = [4.0, 5.0, 6.0, 3.0, 2.0, 1.0, 1.0, 3.0, 6.0, 9.0] | |
let dataPointsSeries1 = yValuesSeries1.enumerated().map { index, yValue in | |
AXDataPoint(x: Double(index), y: yValue) | |
} | |
// 2 | |
let yValuesSeries2 = [6.0, 5.0, 4.0, 7.0, 8.0, 9.0, 9.0, 7.0, 4.0, 1.0] | |
let dataPointsSeries2 = yValuesSeries2.enumerated().map { index, yValue in |
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
// 1 | |
var accessibilityChartDescriptor: AXChartDescriptor? { | |
// 2 | |
get { | |
AXChartDescriptor( | |
title: "Example Graph", | |
summary: "This graph shows example data.", | |
xAxis: xAxis, | |
yAxis: yAxis, | |
series: series |
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
private var series: [AXDataSeriesDescriptor] { | |
// 1 | |
let yValuesSeries = [4.0, 5.0, 6.0, 3.0, 2.0, 1.0, 1.0, 3.0, 6.0, 9.0] | |
let dataPointsSeries = yValuesSeries.enumerated().map { index, yValue in | |
AXDataPoint(x: Double(index), y: yValue) | |
} | |
// 2 | |
return [ | |
AXDataSeriesDescriptor( |
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
private var yAxis: AXNumericDataAxisDescriptor { | |
AXNumericDataAxisDescriptor( | |
title: "The y axis", | |
range: (0...9), | |
gridlinePositions: [], | |
valueDescriptionProvider: { (value: Double) -> String in | |
"\(value)" | |
} | |
) | |
} |
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
private var xAxis: AXNumericDataAxisDescriptor { | |
// 1 | |
AXNumericDataAxisDescriptor( | |
title: "The x axis", | |
// 2 | |
range: (0...9), | |
// 3 | |
gridlinePositions: [], | |
// 4 | |
valueDescriptionProvider: { (value: Double) -> String in |
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 HistoryService { | |
// ... | |
// 6 | |
func record(command: Command) { | |
// Remove all undone actions at top of list. | |
history = Array(history.drop { $0.isUndone} ) | |
// Prepend command. | |
history = [command] + history |
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 HistoryService { | |
// ... | |
// 4 | |
func registerUndoFor(command: Command) { | |
undoManager.registerUndo(withTarget: self) { selfTarget in | |
command.isUndone = true | |
command.reverse() | |
selfTarget.registerRedoFor(command: command) |
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
// 1 | |
func redButtonPressed(_ sender: UIButton) { | |
recordColorChangeCommand(newColor: .red) | |
} | |
// 2 | |
func recordColorChangeCommand(newColor: UIColor) { | |
let currentColor = colorView.backgroundColor | |
let command = Command( | |
execute: { self.colorView.backgroundColor = newColor }, |
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 HistoryService { | |
// 1 | |
let undoManager = UndoManager() | |
var history = [Command]() | |
// 2 | |
var canUndo: Bool { undoManager.canUndo } | |
func undo() { | |
guard canUndo else { return } |
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 Command { | |
var isUndone: Bool | |
let execute: () -> Void | |
let reverse: () -> Void | |
init(execute: @escaping () -> Void, reverse: @escaping () -> Void) { | |
isUndone = false | |
self.execute = execute | |
self.reverse = reverse | |
} |