Swiftlet Utilities provides several useful functions that are common across many apps written in SwiftUI and Xcode. These include features such as testing to see if an app can connect to the internet, etc.
NOTE: Swiftlet Utilities is a replacement for our Action Utilities library specifically designed to work with SwiftUI. Several other features have been modernized and improved as well.
Additionally, many built-in types (such as Color, String and Data) have been extended with useful features such as converting a color to and from a hex string and moving images easily between Data and String types to support Swift's Codable protocol.
Swiftlet Utilities are support on iOS, tvOS, watchOS and macOS.
If you find SwiftletUtilities useful and would like to help support its continued development and maintenance, please consider making a small donation, especially if you are using it in a commercial product:
It's through the support of contributors like yourself, I can continue to build, release and maintain high-quality, well documented Swift Packages like SwiftletUtilities for free.
Swift Package Manager (Xcode 11 and above)
- In Xcode, select the File > Add Package Dependency… menu item.
- Paste
https://github.com/Appracatappra/SwiftletUtilities.gitin the dialog box. - Follow the Xcode's instruction to complete the installation.
Why not CocoaPods, or Carthage, or blank?
Supporting multiple dependency managers makes maintaining a library exponentially more complicated and time consuming.
Since, the Swift Package Manager is integrated with Xcode 11 (and greater), it's the easiest choice to support going further.
General Utilities provide several, general utility classes to handle things such as network connectivity.
The following extensions are provided:
- HTMLEntity - Decodes the given string converting any HTML Entity codes into their resulting characters.
- Reachability - Test to see if we have an active network connection.
Hardware Utilities provide commonly used information about the device an app is running on such as the device type (for example iPhoneX), the OS version (for example iOS 11.1) and if the app can connect to the internet.
The following extensions are provided:
- AppleHardwareType - Deprecated] Used to convert an Apple device model name (in the form
iPhone10,3) to a human readable form (such asiPhoneX). This enum works with theHardwareInformationclass to get the type of device the app is running on. - HardwareInformation - Defines a set of convenience properties and functions when working on Apple devices, such as checking the device model name (
iPhone10,3), getting the device type (iPhoneX), getting the OS version (iOS 11.1), the current device orientation and internet connection state:- isPhone - Returns
trueif the app is running on an iPhone, else returnsfalse. - isPad - Returns
trueif the app is running on an iPad, else returnsfalse. - isTV - Returns
trueif the app is running on an Apple TV, else returnsfalse. - isCar - Returns
trueif the app is running on a CarPlay connected device, else returnsfalse. - isWatch - Returns
trueif the app is running on an Apple Watch, else returnsfalse. - isMac - Returns
trueif the app is running on a Mac laptop or desktop, else returnsfalse. - modelName - Returns the model name of the device the app is running on. For example,
iPhone10,3oriPhone10,6for theiPhone X. - deviceType - Returns the human-readable type of the device that the app is running on (for example
iPhoneX) orunknownif the type cannot be discovered. - osVersion - Returns the version number (for example
iOS 11.1) of the OS installed on the device that the app is running on.
- isPhone - Returns
Swiftlet Extensions provide several useful features to common, built-in SwiftUI and Swift data types such as converting Color to/from hex strings (for example #FF0000), creating Image instances from Base64 encoded strings stored in Data objects and encoding Images as Base64 strings or Data objects.
// Assign a color from a string
let color: Color ~= "#FF0000"
// Initialize a color from a hex string
let green = Color(fromHex: "00FF00")
// Convert color to a hex string
let white = Color.white.toHex()The following extensions are provided:
- Color - Extends
Colorto support the Action Data controls and adds convenience methods for working with colors in aCodable,EncodableorDecodableclass. - Data - Extends
Datato support the Action Data controls and adds convenience methods for working with data properties in aCodable,EncodableorDecodableclass. - Image - Extends
Imageto support the Action Data controls and adds convenience methods for working with image properties in aCodable,EncodableorDecodableclass. - String - Extends
Stringto support the Action Data controls and adds convenience methods for working withImageandColorproperties in aCodable,EncodableorDecodableclass. - Array - Extends
Arraywith new functions for working with collections. - Double - Extends
Doublewith several useful features. - Int - Extends
Intwith several useful features. - @Published - Allows properties that are marked
@Publishedand allows them to beCodablewithEncodeandDecodeconformance. - View - Conditionally apply modifiers depending on the target operating system.
The Package includes full DocC Documentation for all features.
