Skip to content

Instantly share code, notes, and snippets.

@Azat92
Created July 16, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azat92/2941200d9c1cc5d91d54e992660b7fc8 to your computer and use it in GitHub Desktop.
Save Azat92/2941200d9c1cc5d91d54e992660b7fc8 to your computer and use it in GitHub Desktop.
Mysterious EXC_BAD_ACCESS in Swift playground
//: Playground - noun: a place where people can play
import UIKit
protocol Base {
static var key: String { get }
}
protocol BaseChild: Base {
}
struct ChildClass: BaseChild {
static var key: String {
return "key"
}
}
class Worker {
static var defaultWorker: Worker?
func work<T: Base>(entity: T) {
print(T.key)
}
}
class ChildWorker: Worker {
override func work<T: BaseChild>(entity: T) {
print(T.key)
}
}
extension Base {
func work() {
Worker.defaultWorker?.work(entity: self)
}
}
class Test {
static func run() {
let object = ChildClass()
let worker = ChildWorker()
worker.work(entity: object)
Worker.defaultWorker = worker
object.work()
}
}
Test.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment