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.
- In Xcode, select File > Swift Packages > Add Package Dependency.
- Follow the prompts using the URL for this repository
- Select the
SwiftFoundationExtensionslibrary to add to your project
See the LICENSE file.
Informational (Source)
let mainBundleVersion: StringFull version and build number of the main bundle in the format: v[MAJOR].[MINOR].[PATCH]-[BUILD]
let isInstalledFromAppstore: BoolTrue 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 : StrideableDouble 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 == IntAsyncSequence 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 == IntDictionary 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) -> LoggerErrorWithTrace 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