Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/williamFalcon/SwiftTryCatch

Adds try-catch support for Swift
https://github.com/williamFalcon/SwiftTryCatch

Last synced: 3 months ago
JSON representation

Adds try-catch support for Swift

Awesome Lists containing this project

README

        

SwiftTryCatch
=============

Adds try/catch support for Swift.

Simple wrapper built around Objective-C `@try`/`@catch`/`@finally`.

##Usage

### Install via Cocoapods

pod 'SwiftTryCatch'

### Import

If using Frameworks for pods (use_frameworks! flag in Podfile):

import SwiftTryCatch

or import into Obj-C bridging header:

#import "SwiftTryCatch.h"

### Use

SwiftTryCatch.try({
// try something
}, catch: { (error) in
print("\(error.description)")
}, finally: {
// close resources
})

## Notes
It was pointed out that without -fobjc-arc-exceptions flag this will lead to memory leaks

http://clang.llvm.org/docs/AutomaticReferenceCounting.html#exceptions

Therefore, ARC-generated code leaks by default on exceptions, which is just fine if the process is going to be immediately terminated anyway. Programs which do care about recovering from exceptions should enable the option.