Latest 1.0.0
Homepage https://github.com/broadwaylamb/SwiftyNSException
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Authors

Build Status
codecov
Language
Platform
Cocoapods

SwiftyNSException adds conformance to Error protocol for NSException and provides a wrapper function that
catches an Objective-C exception and rethrows it in Swift so you can catch it using the do-catch block.

Requirements

  • Swift 3
  • iOS 8.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+

Installation

CocoaPods

For the latest release in CocoaPods add the following to your Podfile:

use_frameworks!

pod 'SwiftyNSException'

For the latest dev build:

use_frameworks!

pod 'SwiftyHaru', :git => 'https://github.com/broadwaylamb/SwiftyNSException.git', :branch => 'master'

Usage

Use the generic function handle(_:) to wrap some code that can throw an NSException.


import SwiftyNSException

do {

    let result = try handle { () -> String in

        // Some invocation that can throw an NSException

        return "OK"
    }

    // The type of `result` is `String`.

} catch let exception as NSException {

    // Handle the exception

} catch {

    // Handle some other error thrown.

}

Latest podspec

{
    "name": "SwiftyNSException",
    "version": "1.0.0",
    "summary": "A tiny library that lets you catch Objective-C NSExceptions right in your Swift code.",
    "description": "SwiftyNSException provides a single function that wraps a closure that can thrownan Objective-C exception and rethrows the exception as a proper Swift error.",
    "homepage": "https://github.com/broadwaylamb/SwiftyNSException",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Sergej Jaskiewicz": "[email protected]"
    },
    "social_media_url": "http://twitter.com/broadway_lamb",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/broadwaylamb/SwiftyNSException.git",
        "tag": "1.0.0"
    },
    "source_files": [
        "SwiftyNSException/NSException+Swift.{h,m}",
        "SwiftyNSException/SwiftyNSException.h",
        "SwiftyNSException/Wrapper.swift"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This