Swiftpack.co - fizker/swift-extensions as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fizker.
fizker/swift-extensions 1.0.0
A collection of small extensions and custom operators.
⭐️ 0
🕓 1 week ago
.package(url: "https://github.com/fizker/swift-extensions.git", from: "1.0.0")

Extensions for Swift

A collection of small extensions and custom operators.

DocC documentation

How to use

  1. Add .package(url: "https://github.com/fizker/swift-extensions.git", from:"1.0.0") to the list of dependencies in your Package.swift file.
  2. Add .product(name: "FzkExtensions", package: "swift-extensions") to the dependencies of the targets that need to use the models.
  3. Add import FzkExtensions to a file to gain access to the extensions and operators.

Extensions

Array#removing(at index:)

let measurements: [Double] = [1.1, 1.5, 2.9, 1.2, 1.5, 1.3, 1.2]
let removed = measurements.removing(at: 2)
print(removed)
// Prints "[1.1, 1.5, 1.2, 1.5, 1.3, 1.2]"

RandomAccessCollection#[safe index:]

let array = [1,2,3]
assert(array[safe: -1] == nil)
assert(array[safe: 0] == 1)
assert(array[safe: 1] == 2)
assert(array[safe: 2] == 3)
assert(array[safe: 3] == nil)

Operators

Configurator ~

let view = UIView()
view.addGestureRecognizer(UITapGestureRecognizer() ~ {
    $0.numberOfTapsRequired = 2
    $0.modifierFlags = [ .command ]
})

Optional set ??=

// Given the class Foo
class Foo {
    var bar: Int?
}

func ensureValue(foo: Foo) {
    // If foo.bar is nil, it now becomes 1.
    // If it is not nil, it will remain unchanged.
    foo.bar ??= 1
}

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0
1 week ago

Initial release containing the ~ operator, the ??= operator, the [safe:] subscript for RandomAccessCollection and the removing(at index:) function for Array.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics