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
These properties are based on the getRed(_:green:blue:alpha) method.
init?(hex:)
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")
createHex(alpha:hashSymbol:)
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"
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.
These properties are based on the getRed(_:green:blue:alpha) method.
init?(hex:)
This initializer can create an NSColor-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: NSColor? = NSColor(hex: "#ffff00ff")
createHex(alpha:hashSymbol:)
This method creates a hex string from the color instance.
let yellow = NSColor(red: 1, green: 1, blue: 0, alpha: 1)
let hexString: String = yellow.createHex(alpha: true)
print(hexString) // "#ffff00ff"
License
FHExtensions is available under the MIT license. See the LICENSE file for more info.
FHExtensions
Some useful Foundation and UIKit Extensions.
Requirements
Installation
Swift Package Manager
Add the following to the dependencies of your
Package.swift:Manual
Download the Sources folder and drag it into you project.
Usage
Array
subscript(safe index: Index) -> Element?This subscript checks, if the index is in range.
Getting array values works like that:
Setting array values works also safely:
Bundle
versionNumber,buildNumberThe values for the
CFBundleShortVersionStringandCFBundleVersionkey in the info dictionary.CGRect
Coordinates:
x,y,top,bottom,left,right,centerConvenience properties for
CGRectcoordinates.Date
init?(_:_:_:hour:minute:second:timeZone)This initializer can create a
Dateobject by date components. It can fail if a date could not be found which matches the components.JSONDecoder
DateDecodingStrategy.iso8601withFractionalSecondsAn ISO 8601
DateDecodingStrategywith fractional seconds. Something like1999-02-23T09:41:00.000Zwill work with the decoder.JSONEncoder
DateEncodingStrategy.iso8601withFractionalSecondsAn ISO 8601
DateEncodingStrategywith fractional seconds. Something like1999-02-23T09:41:00.000Zwill be the output from the encoder.String
capitalizedFirstA copy of the string where the first letter is capitalized.
UIColor
RGB:
red,green,blue,alphaThese properties are based on the
getRed(_:green:blue:alpha)method.init?(hex:)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.createHex(alpha:hashSymbol:)This method creates a hex string from the color instance.
UIDevice
modelIdentifierWith
UIDevice.current.modelIdentifieryou are able to get the model identifier of the current device asString.UIDirectionalPanGestureRecognizer
A concrete subclass of UIPanGestureRecognizer that cancels if the specified direction does not match.
NSColor
RGB:
red,green,blue,alphaThese properties are based on the
getRed(_:green:blue:alpha)method.init?(hex:)This initializer can create an
NSColor-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.createHex(alpha:hashSymbol:)This method creates a hex string from the color instance.
License
FHExtensions is available under the MIT license. See the LICENSE file for more info.