Convenient operator for optional values
var optionalValue: Int?
...
let value: Int = try optionalValue~!
var optionalInt: Int?
var optionalString: String?
try? someFunc(value1: optionalInt~!, value2: optionalString~!)
//instead of
//if let int = optionalInt, let string = optionalString {
// someFunc(value1: int, value2: string)
//}
...
func someFunc(value1: Int, value2: String)
OptionalProtocol
- protocol that allows you to work with Opational<Wrapped>
in some interesting ways:
extension Array where Element: OptionalProtocol {...}
CocoaPods Add the following line to your Podfile:
pod 'UnwrapOperator'
and run pod update
from the podfile directory first.
Swift Package Manager
Create a Package.swift
file.
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/UnwrapOperator.git", from: "0.1.0")
],
targets: [
.target(name: "SomeProject", dependencies: ["UnwrapOperator"])
]
)
$ swift build
Voidilov, [email protected]
UnwrapOperator is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 0 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics