Latest 0.1.1
Homepage https://github.com/mr-v/NSErrorPointerWrapper
License MIT
Platforms ios 8.0, requires ARC
Authors

Wrapper for handling iOS SDK APIs that take in error by reference.

Some of the benefits:

  • Simplified handling of methods that take in NSErrorPoint.
  • No more declaring that pesky NSError variable to pass by reference (use $0 shorthand argument name in closure passed to the wrapper).
  • Chaining handlers for success and failure.
  • Streamlined downcasting handling (needed because often the result of those methods is AnyObject? instance).

Usage

tryWithErrorPointer { NSJSONSerialization.JSONObjectWithData(data, options: nil, error: $0) }
                .onError { error in /* handle error */ }
                .onSuccess { result in /* handle success */ } }

With casting:

tryWithErrorPointer(castResultTo: NSDictionary.self) { NSJSONSerialization.JSONObjectWithData(data, options: nil, error: $0) }
                .onError { error in /* handle error */ }
                .onSuccess { result in /* handle success */ } }

For more details check tests and those resources:

Installation with CocoaPods

  • You need to use CocoaPods version that supports Frameworks: at least 0.36.0. Currently it’s a beta feature, to install it update CocoaPods: gem install cocoapods --prerelease.
  • Just add the following line to the Podfile and run pod update:
    pod 'NSErrorPointerWrapper'

Latest podspec

{
    "name": "NSErrorPointerWrapper",
    "version": "0.1.1",
    "summary": "Simplified error handling for Cocoa Touch APIs in Swift",
    "description": "Swift wrapper functions that simplify handling of methods that take in `NSErrorPoint`. Some of the benefits:nn- no more declaring that pesky `NSError` variable to pass by reference (use `$0` shorthand argument name in closure passed to wrapper)n- handlers chaining for success and failuren- streamlined downcasting handling (needed because often the result of those methods is `AnyObject?` instance)n",
    "homepage": "https://github.com/mr-v/NSErrorPointerWrapper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "mr-v": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/mr-v/NSErrorPointerWrapper.git",
        "tag": "0.1.1"
    },
    "source_files": "NSErrorPointerWrapper",
    "requires_arc": true
}

Pin It on Pinterest

Share This