NSOperation property overrides (isExecuting / isFinished)

后端 未结 3 739
天涯浪人
天涯浪人 2020-12-23 18:42

I am subclassing NSOperation in Swift and need to override the isExecuting and isFinished properties since I am overriding the s

3条回答
  •  悲&欢浪女
    2020-12-23 19:15

    From the swift book:

    You can present an inherited read-only property as a read-write property by providing both a getter and a setter in your subclass property override.

    I think you'll find that this works:

    override var executing : Bool {
        get { return _executing }
        set { 
            willChangeValueForKey("isExecuting")
            _executing = newValue 
            didChangeValueForKey("isExecuting")
        }
    }
    private var _executing : Bool
    

提交回复
热议问题