NSManagedObjectContext performBlock() & performBlockAndWait() don't accept throwing closures
| Originator: | stephen.groom | ||
| Number: | rdar://21745663 | Date Originated: | 09-Jul-2015 04:11 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Swift 2b3 |
| Classification: | Other Bug | Reproducible: | Always |
The methods performBlockAndWait(_:) and performBlock(_:) do not accept a closure which throws. “Invalid conversion from throwing function of type '() throws -> _' to non-throwing function type '() -> Void’”. I believe something like saving the context is a common use case for this:
public func saveContexts() throws {
do {
backgroundContext.performBlockAndWait { [weak self] in
try self?.backgroundContext.save()
}
mainContext.performBlockAndWait { [weak self] in
try self?.mainContext.save()
}
}
catch let error {
throw error
}
}
Marking performBlockAndWait and performBlock as rethrows would allow them to take a throwing closure and propagate the error to the caller.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!