Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/broadwaylamb/swiftynsexception
A tiny library that lets you catch Objective-C NSExceptions right in your Swift code.
https://github.com/broadwaylamb/swiftynsexception
Last synced: 21 days ago
JSON representation
A tiny library that lets you catch Objective-C NSExceptions right in your Swift code.
- Host: GitHub
- URL: https://github.com/broadwaylamb/swiftynsexception
- Owner: broadwaylamb
- License: mit
- Created: 2017-05-22T17:07:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-28T10:27:56.000Z (over 2 years ago)
- Last Synced: 2024-11-16T17:41:48.050Z (about 1 month ago)
- Language: Swift
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftyNSException
[![Build Status](https://travis-ci.org/broadwaylamb/SwiftyNSException.svg?branch=master)](https://travis-ci.org/broadwaylamb/SwiftyNSException)
[![codecov](https://codecov.io/gh/broadwaylamb/SwiftyNSException/branch/master/graph/badge.svg)](https://codecov.io/gh/broadwaylamb/SwiftyNSException)
![Language](https://img.shields.io/badge/Swift-5.0-orange.svg)
![Platform](https://img.shields.io/cocoapods/p/SwiftyNSException.svg?style=flat)
![Cocoapods](https://img.shields.io/cocoapods/v/SwiftyNSException.svg?style=flat)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 5
* 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`:
```ruby
use_frameworks!pod 'SwiftyNSException'
```For the latest dev build:
```ruby
use_frameworks!pod 'SwiftyNSException', :git => 'https://github.com/broadwaylamb/SwiftyNSException.git', :branch => 'master'
```## Usage
Use the generic function `handle(_:)` to wrap some code that can throw an NSException.
```swift
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.
}
```