Functions

The following functions are available globally.

  • Create an UIColor or NSColor in format RGBA.

    Declaration

    Swift

    public func RGBA(_ red: Int, _ green: Int, _ blue: Int, _ alpha: Float) -> Color

    Parameters

    red

    Red value.

    green

    Green value.

    blue

    Blue value.

    alpha

    Alpha value.

    Return Value

    Returns the created UIColor or NSColor.

  • Create an UIColor or NSColor in format ARGB.

    Declaration

    Swift

    public func ARGB(_ alpha: Float, _ red: Int, _ green: Int, _ blue: Int) -> Color

    Parameters

    alpha

    Alpha value.

    red

    Red value.

    green

    Green value.

    blue

    Blue value.

    Return Value

    Returns the created UIColor or NSColor.

  • Create an UIColor or NSColor in format RGB.

    Declaration

    Swift

    public func RGB(_ red: Int, _ green: Int, _ blue: Int) -> Color

    Parameters

    red

    Red value.

    green

    Green value.

    blue

    Blue value.

    Return Value

    Returns the created UIColor or NSColor.

  • Compare OS versions.

    Declaration

    Swift

    public func osVersionEqual(_ version: String) -> Bool

    Parameters

    version

    Version, like 9.0.

    Return Value

    Returns true if equal, otherwise false.

  • Compare OS versions.

    Declaration

    Swift

    public func osVersionGreaterThan(_ version: String) -> Bool

    Parameters

    version

    Version, like 9.0.

    Return Value

    Returns true if greater, otherwise false.

  • Compare OS versions.

    Declaration

    Swift

    public func osVersionGreaterThanOrEqual(_ version: String) -> Bool

    Parameters

    version

    Version, like 9.0.

    Return Value

    Returns true if greater or equal, otherwise false.

  • Compare OS versions.

    Declaration

    Swift

    public func osVersionLessThan(_ version: String) -> Bool

    Parameters

    version

    Version, like 9.0.

    Return Value

    Returns true if less, otherwise false.

  • Compare OS versions.

    Declaration

    Swift

    public func osVersionLessThanOrEqual(_ version: String) -> Bool

    Parameters

    version

    Version, like 9.0.

    Return Value

    Returns true if less or equal, otherwise false.

  • NSLocalizedString without comment parameter.

    Declaration

    Swift

    public func NSLocalizedString(_ key: String) -> String

    Parameters

    key

    The key of the localized string.

    Return Value

    Returns a localized string.

  • Creates a flatten array.

    Example:

    [1, 2, [3, [4]]] -> [1, 2, 3, 4]
    

    Declaration

    Swift

    public func flatten<T>(_ array: [T]) -> [T]

    Parameters

    array

    Array bo te flattened.

    Return Value

    Returns a flatten array.

  • Degrees to radians conversion.

    Declaration

    Swift

    public func degreesToRadians(_ degrees: Float) -> Float

    Parameters

    degrees

    Degrees to be converted.

    Return Value

    Returns the convertion result.

  • Radians to degrees conversion.

    Declaration

    Swift

    public func radiansToDegrees(_ radians: Float) -> Float

    Parameters

    radians

    Radians to be converted.

    Return Value

    Returns the convertion result.

  • Create a random integer between the given range.

    Declaration

    Swift

    @available(*, deprecated: 3.2, renamed: "Int.random", message: "`randomInt(﹚` is deprecated and will be removed in a future version of BFKit-Swift.")
    public func randomInt(min minValue: Int = 0, max maxValue: Int = 100) -> Int

    Parameters

    minValue

    Mininum random value. Default is 0.

    maxValue

    Maxinum random value. Default is 1.

    Return Value

    Returns the created random integer.

  • Create a random integer between the given range. Example: randomInt(-500…100).

    Declaration

    Swift

    @available(*, deprecated: 3.2, renamed: "Int.random", message: "`randomInt(﹚` is deprecated and will be removed in a future version of BFKit-Swift.")
    public func randomInt(range: ClosedRange<Int>) -> Int

    Parameters

    range

    Range random value.

    Return Value

    Returns the created random integer.

  • Create a random float between the given range.

    Declaration

    Swift

    @available(*, deprecated: 3.2, renamed: "Float.random", message: "`randomFloat(﹚` is deprecated and will be removed in a future version of BFKit-Swift.")
    public func randomFloat(min minValue: Float = 0, max maxValue: Float = 1) -> Float

    Parameters

    minValue

    Mininum random value. Default is 0.

    maxValue

    Maxinum random value. Default is 1.

    Return Value

    Returns the created random float.

  • Create a random float between the given range. Example: randomFloat(-500…100).

    Declaration

    Swift

    @available(*, deprecated: 3.2, renamed: "Float.random", message: "`randomFloat(﹚` is deprecated and will be removed in a future version of BFKit-Swift.")
    public func randomFloat(range: ClosedRange<Float>) -> Float

    Parameters

    range

    Range random value.

    Return Value

    Returns the created random float.

  • Returns true if left it is in right range but not equal. If you want to check if its even equal use the <=> operator.

    Declaration

    Swift

    public func <> <T>(left: T, right: (T, T)) -> Bool where T : Comparable

    Parameters

    left

    Left number to be compared.

    right

    Right tuple to be compared (Number, Number).

    Return Value

    Returns true if left it is in right range but not equal.

  • Returns true if left is in right range or equal.

    Declaration

    Swift

    public func <=> <T>(left: T, right: (T, T)) -> Bool where T : Comparable

    Parameters

    left

    Left number to be compared.

    right

    Right tuple to be compared (Number, Number).

    Return Value

    Returns true if left it is in right range or equal.

  • Returns defaultValue if optional is nil, otherwise returns optional.

    Declaration

    Swift

    public func ??? <T>(optional: T?, defaultValue: @autoclosure () -> String) -> String

    Parameters

    optional

    The optional variable.

    defaultValue

    The default value.

    Return Value

    Returns defaultValue if optional is nil, otherwise returns optional.

  • Runs a block on main thread.

    Declaration

    Swift

    public func runOnMainThread(_ block: @escaping () -> Void)

    Parameters

    block

    Block to be executed.

  • Runs a block in background.

    Declaration

    Swift

    public func runInBackground(_ block: @escaping () -> Void)

    Parameters

    block

    block Block to be executed.