Trying to backport NSPersistentContainer.performBackgroundTask
for iOS < 15 which has the following signature:
public func performBackgroundTask<T>(_ block: @escaping (NSManagedObjectContext) throws -> T) async rethrows -> T
But getting the following error from compiler (5.8):
Call can throw, but the error is not handled; a function declared 'rethrows' may only throw if its parameter does
Source:
extension NSPersistentContainer {
@backDeployed(before: iOS 15.0)
public final func performBackgroundTask<T>(_ block: @escaping (NSManagedObjectContext) throws -> T) async rethrows -> T {
return try await withCheckedThrowingContinuation { continuation in
performBackgroundTask { context in
continuation.resume(with: Result { try block(context) })
}
}
}
}
Is there any way to guarantee that the function is definitely rethrowing or at least silence the compiler?
ps: maybe that's what I am looking for Pitch: Fix rethrows checking and add rethrows(unsafe)