Generic NSOperation subclass loses NSOperation functionality

后端 未结 3 1556
攒了一身酷
攒了一身酷 2020-12-01 14:54

Today I\'ve met one weird issue when I was trying to \'generalize\' my \'CoreData importing operations\'. It appeared that if I create a generic subclass of NSOperation the

3条回答
  •  旧巷少年郎
    2020-12-01 15:32

    Workaround: You can create NSOperation subclass (no generic), override main and call you own 'execute' func, which can be overriden by generic subclasses. Example:

    class SwiftOperation : NSOperation {
    
        final override func main() {
            execute()
        }
    
        func execute() {
        }
    
    }
    
    class MyOperation : SwiftOperation {
    
        override func execute() {
            println("My operation main was called")
        }
    
    }
    

提交回复
热议问题