I have a maybe silly question. I coming from programming languages with exception handling, e.g. C++ and C#. At the time of Swift 1 I was confronted with the Cocoa Style with error objects (which somewhat reminded me at the ErrorObject in Microsoft COM).
After a time I began to use for my side project app an error handling pattern, in which I used a function parameter (closure) for error handling:
public typealias FailureBlock = (error:NSError!)->Void
JournalEntryStorage.instance.createJournalEntry(journalInfo, failure:
{
error in
NSLog("Watch App saveNewEntryInJournal: \(error.description)")
})
This solution seems nice at the time, because the function parameter forces me to code the error handling logic or I could simply make a call to a passed error handler function.
Now we have a solid error handling in place with Swift 2. Should I change my code completely to the new pattern? There is a lot of code.
How do you deal with your (legacy) code and the new error pattern?
By the way: I found the original Cocoa way with passing an error pointer and dealing with it so ugly in Swift 1. Maybe my method is more ugly but for me it seemed working.