You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Swift 5 on Xcode 10.2: a Swift function which throws, when called inside a trap block, needs be wrapped in its own do { … try … } catch. This is because trap takes a non-throwing block as an argument.
I encountered this, for instance, with NSManagedObjectContext.save – it is a throwing function in Swift, but may also throw an Objective-C exception in case of invalid data or constraint violation.
(I tried making trap accept a throwing function myself, but it turned out not to be trivial, since Swift doesn't automatically translate an Objective-C block parameter taking NSError** into a Swift throwing function. The following link might be useful, I haven't had time to experiment further: https://stackoverflow.com/questions/49324917/swift-try-inside-objective-c-block)
The text was updated successfully, but these errors were encountered:
Using Swift 5 on Xcode 10.2: a Swift function which
throws
, when called inside atrap
block, needs be wrapped in its owndo { … try … } catch
. This is becausetrap
takes a non-throwing block as an argument.I encountered this, for instance, with
NSManagedObjectContext.save
– it is a throwing function in Swift, but may also throw an Objective-C exception in case of invalid data or constraint violation.(I tried making
trap
accept a throwing function myself, but it turned out not to be trivial, since Swift doesn't automatically translate an Objective-C block parameter takingNSError**
into a Swift throwing function. The following link might be useful, I haven't had time to experiment further: https://stackoverflow.com/questions/49324917/swift-try-inside-objective-c-block)The text was updated successfully, but these errors were encountered: