TaskOperation

open class TaskOperation : Operation, @unchecked Sendable

任务操作类,可继承或直接使用

  • 任务句柄,执行完成需调用task.finish(error:)

    Declaration

    Swift

    open var taskBlock: (@Sendable (TaskOperation) -> Void)?
  • 是否在主线程执行,会阻碍UI渲染,默认false

    Declaration

    Swift

    open var onMainThread: Bool
  • 任务错误信息

    Declaration

    Swift

    open private(set) var error: Error? { get }
  • Undocumented

    Declaration

    Swift

    override public init()
  • Undocumented

    Declaration

    Swift

    public convenience init(
        onMainThread: Bool = false,
        queuePriority: Operation.QueuePriority = .normal,
        taskBlock: (@Sendable (TaskOperation) -> Void)?
    )
  • 子类可重写,默认调用taskBlock,任务完成需调用finish(error:)

    Declaration

    Swift

    @objc
    open func executeTask()
  • 是否主线程执行,子类可重写,会阻碍UI渲染,默认返回onMainThread

    Declaration

    Swift

    open func needMainThread() -> Bool
  • 标记任务完成,error为空表示任务成功

    Declaration

    Swift

    open func finish(error: Error? = nil)
  • Undocumented

    Declaration

    Swift

    override open func start()
  • Undocumented

    Declaration

    Swift

    override open func cancel()
  • Undocumented

    Declaration

    Swift

    override open var isAsynchronous: Bool { get }
  • Undocumented

    Declaration

    Swift

    override open var isReady: Bool { get }
  • Undocumented

    Declaration

    Swift

    override open var isFinished: Bool { get }
  • Undocumented

    Declaration

    Swift

    override open var isExecuting: Bool { get }