MainActor

extension MainActor
  • 主Actor安全异步执行句柄

    Declaration

    Swift

    public static func runAsync(execute block: @escaping @MainActor @Sendable () -> Void)
  • 当主线程时执行句柄,非主线程不执行

    Declaration

    Swift

    public static func runSyncIf(execute block: @MainActor () -> Void)
  • 当主线程时执行句柄,非主线程执行另一个句柄

    Declaration

    Swift

    public static func runSyncIf<T>(execute block: @MainActor () -> T, otherwise: () -> T) -> T where T : Sendable
  • 主Actor安全异步执行deinit句柄

    Declaration

    Swift

    public static func runDeinit(execute block: @escaping @MainActor @Sendable () -> Void)
  • 主Actor安全异步执行deinit句柄,可携带参数(非释放对象)

    Declaration

    Swift

    public static func runDeinit<T>(object: T, execute block: @escaping @MainActor @Sendable (T) -> Void) where T : Sendable