Created
July 16, 2017 22:24
-
-
Save Azat92/2941200d9c1cc5d91d54e992660b7fc8 to your computer and use it in GitHub Desktop.
Mysterious EXC_BAD_ACCESS in Swift playground
This file contains 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
//: 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