I have a class that inherits from NSOperation and a protocol that the class should conform to:
protocol OperationProtocol { }
class Operation : NSOperation, OperationProtocol {}
I would like to make every operation have a main() method implemented in the Protocol which is called when the operation is run from a queue.
I tried this:
extension OperationProtocol where Self: NSOperation {
func main() {
doMyStuff()
}
}
This main method isn't called. Putting "override" before it raises compiler error (method does not override method in superclass)
The only way I could make it, was naming the implementing function something else than "main()" and then override main() in the Operation and call the implementation from Protocol
class Operation : NSOperation, OperationProtocol {
override func main() {
self.elseThanMain()
}
}
But I don't want to override main() in every subclass of Operation.
Is this even possible?
Thanks