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
| case 3 where cell.state == .dead: | |
| let liveCell = Cell(x: cell.x, y: cell.y, state: .alive) | |
| updatedCells.append(liveCell) |
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 livingNeighbors = liveCells.filter { $0.isNeighbor(to: cell) } |
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
| switch livingNeighbors.count { | |
| case 2...3 where cell.state == .alive: | |
| updatedCells.append(cell) | |
| } |
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 updatedCells = [Cell]() | |
| let liveCells = cells.filter { $0.state == .alive } | |
| for cell in cells { | |
| } | |
| cells = updatedCells |
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 view = WorldView(worldSize: 10, cellSize: 10) | |
| PlaygroundPage.current.liveView = view |
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
| for cell in world.cells { | |
| let rect = CGRect(x: cell.x * cellSize, y: cell.y * cellSize, width: cellSize, height: cellSize) | |
| let color = cell.state == .alive ? UIColor.green.cgColor : UIColor.white.cgColor | |
| context?.addRect(rect) | |
| context?.setFillColor(color) | |
| context?.fill(rect) | |
| } |
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 context = UIGraphicsGetCurrentContext() | |
| context?.saveGState() |
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
| public override func draw(_ rect: CGRect) { | |
| } |
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
| public override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| } |
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
| public required init?(coder aDecoder: NSCoder) { | |
| fatalError("Not implemented") | |
| } |