Swiftpack.co - FelixHerrmann/FHExtensions as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Some useful Foundation and UIKit Extensions.
.package(url: "https://github.com/FelixHerrmann/FHExtensions.git", from: "1.7.0")


Version License Tweet

Some useful Foundation and UIKit Extensions.

Will be expanded over time.


  • macOS 10.10+
  • iOS 9.0+
  • tvOS 9.0+


Swift Package Manager

Add the following to the dependencies of your Package.swift:

.package(url: "https://github.com/FelixHerrmann/FHExtensions.git", from: "x.x.x")


Download the files in the Sources folder and drag them into you project.



subscript(safe index: Index) -> Element?

This subscript checks, if the index is in range.

Getting array values works like that:

let array = [0, 1, 2]

print(array[1]) // 1
print(array[safe: 1]) // Optional(1)

print(array[3]) // Fatal error: Index out of range
print(array[safe: 3]) // nil

Setting array values works also safely:

var array = [0, 1, 2]

array[safe: 2] = 3
print(array) // [0, 1, 3]

array[safe: 3] = 4
print(array) // [0, 1, 3]


versionNumber, buildNumber

The values for the CFBundleShortVersionString and CFBundleVersion key in the info dictionary.


Coordinates: x, y, top, bottom, left, right, midX, midY, center

Convenience properties for CGRect coordinates.

These properties also contains setters which will recreate the frame entirely.



This initializer can create a Date object by date components. It can fail if a date could not be found which matches the components.

let date = Date(23, 2, 1999)
let dateWithTimeAndTimeZone = Date(23, 2, 1999, hour: 9, minute: 41, second: 0, timeZone: TimeZone(secondsFromGMT: 0))

The time values and time zone are optional.



An ISO 8601 DateDecodingStrategy with fractional seconds. Something like 1999-02-23T09:41:00.000Z will work with the decoder.



An ISO 8601 DateEncodingStrategy with fractional seconds. Something like 1999-02-23T09:41:00.000Z will be the output from the encoder.



A copy of the string where the first letter is capitalized.


RGB: red, green, blue, alpha

These properties are based on the getRed(_:green:blue:alpha) method.


This initializer can create a UIColor object by a hex string. It can fail if the string has not the correct format. It allows hex strings with and without alpha, the hash symbol is not required and capitalization does not matter.

let yellow: UIColor? = UIColor(hex: "#ffff00ff")


This method creates a hex string from the color instance.

let yellow = UIColor(red: 1, green: 1, blue: 0, alpha: 1)
let hexString: String = yellow.createHex(alpha: true)
print(hexString) // "#ffff00ff"



With UIDevice.current.modelIdentifier you are able to get the model identifier of the current device as String.

This works also on Mac (Catalyst).


A concrete subclass of UIPanGestureRecognizer that cancels if the specified direction does not match.

let directionalPanRecognizer = UIDirectionalPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
directionalPanRecognizer.direction = .vertical

The touchesMoved(_:with:) is not called on trackpad and mouse events. Use the UIGestureRecognizerDelegate.gestureRecognizerShouldBegin(_:) instead if the allowedScrollTypesMask is set to UIScrollTypeMask.discrete or UIScrollTypeMask.continuous.


FHExtensions is available under the MIT license. See the LICENSE file for more info.


Stars: 1
Last commit: 4 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

6 weeks ago

• removed UserDefault (it is now in a separate package) • Date init timeZone attribute added • CI workflows added • Unit tests fixed

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