Objective-C compatible wrapper of Swift's Result type
Latest release: 27.10.2020 • version 1.0.0
Requirements: iOS 9.0+ • macOS 10.10+ • tvOS 9.0+ • watchOS 2.0+ • Swift 5.1+ / Xcode 11.3+
Swift version | Project version |
---|---|
Swift 5.1 | v1.0.0 |
Tested with carthage version
: 0.36
Add this to Cartfile
git "https://github.com/T1T4N/NSResult.git" ~> 1.0
Tested with swift build --version
: Swift Package Manager - Swift 5.3.0
// swift-tools-version:5.1
dependencies: [
.package(url: "https://github.com/T1T4N/NSResult.git", from: "1.0.0")
]
Tested with pod --version
: 1.10.0
platform :osx, '10.10'
use_frameworks!
target 'MyApp' do
pod 'NSResultKit', :git => "https://github.com/T1T4N/NSResult.git", :tag => "1.0.0"
end
Check the example playground or the example app in the project.
This is a Swift library meant to be used in mixed-language projects where the codebase still has a considerable amount of Objective-C.
This is a simple @objc
class that inherits from NSObject
and has one single property base: Result<Any, Error>
. This property is only accessible on the Swift side, but NSResult
can initialized from Objective-C using the following methods:
[NSResult success:]
[NSResult failure:]
Used on the Swift side to restore type safety to the underlying Result
object.
Used on the Objective-C side to cleanly separate the logic for handling a success value from the one for handling a failure.
[result performSuccess:^(id _Nonnull value) orFailure:^(NSError * _Nonnull error)]
[result performBlock:^(id _Nullable successValue, NSError * _Nullable failureError)]