A collection of small extensions and custom operators.
.package(url: "https://github.com/fizker/swift-extensions.git", from:"1.0.0")
to the list of dependencies in your Package.swift file..product(name: "FzkExtensions", package: "swift-extensions")
to the dependencies of the targets that need to use the models.import FzkExtensions
to a file to gain access to the extensions and operators.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)
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
}
link |
Stars: 0 |
Last commit: 2 weeks ago |
Added helpers for Date
, JSONEncoder
and JSONDecoder
for handling ISO 8601 dates with fractional seconds.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics