Swift Package Index

SwiftTryCatch

https://github.com/seanparsons/swifttrycatch.git

Adds try-catch support for Swift


Compatibility

  • 1.0.0
    5.3
    5.2
    5.1
    5.0
    4.2
  • master
    5.3
    5.2
    5.1
    5.0
    4.2
  • 1.0.0
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
  • master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS

SwiftTryCatch

Adds try/catch support for Swift.

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

Note: This repository was originally forked from https://github.com/williamFalcon/SwiftTryCatch and updated to work with Swift 2.0, since the original API conflicted with new try/catch keywords introduced by new Swift version.

##Usage

Install via Swift Package Manager

To use this specific repository version of SwiftTryCatch add it to your Package.swift manifest.

import PackageDescription

let package = Package(
    name: "YourModule",
    dependencies: [
        .Package(url: "https://github.com/seanparsons/SwiftTryCatch.git", majorVersion: 1, minor: 1),
    ]
)

Install via CocoaPods

To use this specific repository version of SwiftTryCatch use the following pod definition:

pod 'SwiftTryCatch', :git => 'https://github.com/ravero/SwiftTryCatch.git'

This will use the podspec from this forked repository with the API signature changes.

Create bridging header

  • When prompted with "Would you like to configure an Obj-C bridging header?", press "Yes".
  • Go to bridging header and add:
#import "SwiftTryCatch.h"

Use

SwiftTryCatch.tryBlock({
        // try something
    }, catchBlock: { (error) in
        println("\(error.description)")
    }, finallyBlock: {
        // close resources
    })