SwiftFoundationExtensions

1.0.0

An open source library with some useful extensions and utilities for the core Foundation Swift libraries
xiiagency/SwiftFoundationExtensions

What's New

v1.0.0

2022-05-03T19:33:26Z

First public release

SwiftFoundationExtensions Library

GitHub

An open source library with some useful extensions and utilities for the core Foundation Swift libraries. Developed as re-usable components for various projects at XII's iOS, macOS, and watchOS applications.

Installation

Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Follow the prompts using the URL for this repository
  3. Select the SwiftFoundationExtensions library to add to your project

License

See the LICENSE file.

Included Extensions / API

Informational (Source)

let mainBundleVersion: String

Full version and build number of the main bundle in the format: v[MAJOR].[MINOR].[PATCH]-[BUILD]


let isInstalledFromAppstore: Bool

True if the main bundle was installed from the app store (not in a sandbox environment), false otherwise.

Date Extensions (Source)

var startOfWeek: Date { get }

var daysRemainingThisWeek: Int { get }

var startOfMonth: Date { get }

var startOfYear: Date { get }

init(year: Int, month: Int, day: Int)

Comparable Extensions (Source)

func clamped(to limits: ClosedRange<Self>) -> Self

func clamped(to limits: Range<Self>) -> Self where Self : Strideable

Double Extensions (Source)

func isCloseTo(_ other: Double) -> Bool

func isCloseToOrGreaterThan(_ other: Double) -> Bool

func isCloseToOrLessThan(_ other: Double) -> Bool

var roundedUp: Int { get }

var roundedDown: Int { get }

Sequence Extensions (Source)

func sum() -> Double where Element == Double

func sumOfSquares() -> Double where Element == Double

func sum() -> Int where Element == Int

func sumOfSquares() -> Int where Element == Int

func asDictionary<Key : Hashable, Value>() -> [Key: Value]
  where Element == (Key, Value)

func mapToDictionary<Key : Hashable, MappedValue>(
  _ pairExtractor: @escaping (Element) throws -> (Key, MappedValue)
) rethrows -> [Key: MappedValue]

func grouped<Key : Hashable>(
  _ keyExtractor: @escaping (Element) throws -> Key
) rethrows -> [Key: [Element]]

EnumeratedSequence Extensions (Source)

func mapToDictionary<Key : Hashable, MappedValue>(
  _ pairExtractor: @escaping (Iterator.Element) throws -> (Key, MappedValue)
) rethrows -> [Key: MappedValue]

Collection Extensions (Source)

func average() -> Double where Element == Double

func average() -> Int where Element == Int

AsyncSequence Extensions (Source)

func sum() async rethrows -> Double where Element == Double

func sumOfSquares() async rethrows -> Double where Element == Double

func sum() async rethrows -> Int where Element == Int

func sumOfSquares() async rethrows -> Int where Element == Int

Dictionary Extensions (Source)

mutating func increment(key: Key, by value: Value) where Value == Int

mutating func increment(key: Key) where Value == Int

mutating func decrement(key: Key) where Value == Int

mutating func increment(key: Key, by value: Value) where Value == Double

mutating func increment(key: Key) where Value == Double

mutating func decrement(key: Key) where Value == Double

mutating func incrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey,
  by value: Int
) where Value == Dictionary<SubKey, Int>

mutating func incrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey
) where Value == Dictionary<SubKey, Int>

mutating func decrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey
) where Value == Dictionary<SubKey, Int>

mutating func incrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey,
  by value: Double
) where Value == Dictionary<SubKey, Double>

mutating func incrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey
) where Value == Dictionary<SubKey, Double>

mutating func decrementSubMapValue<SubKey : Hashable>(
  key: Key,
  subKey: SubKey
) where Value == Dictionary<SubKey, Double>

mutating func append<InnerValue>(
  value: InnerValue,
  for key: Key
) where Value == Array<InnerValue>

func inverted() -> [Value: Key] where Value : Hashable

func inverted() -> [Value.Element: [Key]]
  where Value : Sequence, Value.Element : Hashable

mutating func set<SubKey : Hashable, SubValue>(
  value: SubValue,
  key: Key,
  subKey: SubKey
) where Value == Dictionary<SubKey, SubValue>

Logger Extensions (Source)

static func loggerFor(_ category: String) -> Logger

static func loggerFor<Type>(_ type: Type.Type) -> Logger

ErrorWithTrace struct (Source)

A Specialized Error that captures the file/line number of a thrown error to aid in debugging.

Conforms to: Error and CustomStringConvertible

let file: String

let line: Int

let error: Error

var description: String { get }

var localizedDescription: String { get }

Error Extensions (Source)

var description: String { get }

func withTrace(filePath: String = #file, line: Int = #line) -> ErrorWithTrace

func castError<Target : Error>(to type: Target.Type) -> Target?

ElapsedTimer Utility (Source)

A utility for tracking/reporting the elapsed time between operations.

Utilizes CFAbsoluteTimeGetCurrent to get an accurate measure of the current time on the device and the difference between these measures as the elapsed time.

init()

func reset()

func elapsedTimeSeconds() -> Double

func elapsedTimeSecondsText() -> String

func elapsedTimeSecondsAndReset() -> Double

func elapsedTimeSecondsTextAndReset() -> String

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Oct 21 2024 17:55:17 GMT-0900 (Hawaii-Aleutian Daylight Time)