Skip to content

Instantly share code, notes, and snippets.

View dmytro-anokhin's full-sized avatar
🔨

Dmytro Anokhin dmytro-anokhin

🔨
  • London
View GitHub Profile
class Object {
var anotherObject: AnotherObject
}
class Object {
var children: [Object]
}
protocol Component {
func foo()
}
class Composite: Component {
var children: [Component] = []
func foo() {
// Generated interface for UIView.h in Swift 4
extension UIView {
open var subviews: [UIView] { get }
}
// Generated interface for UIViewController.h in Swift 4
extension UIViewController {
@available(iOS 5.0, *)
open var childViewControllers: [UIViewController] { get }
}
protocol Task {
func run(_ completion: @escaping (_ task: Task) -> Void)
}
let tasks: [Task] = // List of concrete tasks
let group = DispatchGroup()
for task in tasks {
group.enter()
task.run({ task in
group.leave()
})
}
class CompositeTask: Task {
let tasks: [Task]
init(_ tasks: [Task]) {
self.tasks = tasks
}
func run(_ completion: @escaping (Task) -> Void) {
let group = DispatchGroup()
let compositeTask = CompositeTask(tasks)
compositeTask.run() { _ in
print("All tasks completed")
}