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 touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { | |
| world.updateCells() | |
| setNeedsDisplay() | |
| } |
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 func autoRun() { | |
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { | |
| self.world.updateCells() | |
| self.setNeedsDisplay() | |
| self.autoRun() | |
| } | |
| } |
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: 100, cellSize: 5) | |
| view.autoRun() | |
| 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
| extension UIControl { | |
| /// Typealias for UIControl closure. | |
| public typealias UIControlTargetClosure = (UIControl) -> () | |
| private class UIControlClosureWrapper: NSObject { | |
| let closure: UIControlTargetClosure | |
| init(_ closure: @escaping UIControlTargetClosure) { | |
| self.closure = closure | |
| } |
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 button = UIButton() | |
| button.addAction(for: .touchUpInside) { (button) in | |
| // Run code | |
| } | |
| let slider = UISlider() | |
| slider.addAction(for: .valueChanged) { (slider) in | |
| // Run code | |
| } |
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
| extension UITableViewCell { | |
| static var reuseIdentifier: String { | |
| return NSStringFromClass(self) | |
| } | |
| } |
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
| extension UITableView { | |
| public func register<T: UITableViewCell>(cellClass: T.Type) { | |
| register(cellClass, forCellReuseIdentifier: cellClass.reuseIdentifier) | |
| } | |
| } |
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
| extension UITableView { | |
| public func dequeue<T: UITableViewCell>(cellClass: T.Type) -> T? { | |
| return dequeueReusableCell(withIdentifier: cellClass.reuseIdentifier) as? T | |
| } | |
| public func dequeue<T: UITableViewCell>(cellClass: T.Type, forIndexPath indexPath: IndexPath) -> T { | |
| guard let cell = dequeueReusableCell( | |
| withIdentifier: cellClass.reuseIdentifier, for: indexPath) as? T else { | |
| fatalError( |
OlderNewer