A collection of useful Swift / SwiftUI extensions.
Framework | Extension | Description |
---|---|---|
Foundation | CGFloat+Degrees |
Provides convenient CGFloat constants for common angle measurements in radians. Examples:- Rotate a view by 90 degrees: view.transform = CGAffineTransform(rotationAngle: .degrees90) - Set a circular progress bar to half: progressBar.progress = .degrees180 / .degrees360 |
| Collection+Safe |
Avoids Fatal error: Index out of range (out of bounds index) Returns the element at the specified index if it is within bounds; otherwise nil . |
| Optional+ToString |
Allows printing nil when the optional is nil , or the wrapped value itself. For example: 123 instead of Optional(123) . |
| String+Decimal |
Formats a numeric string to a specified number of decimal places. For example: "351.6632141234" becomes "351.66" . |
| String+EmptyOrWhiteSpace |
Returns true if the string is empty or contains only whitespace and newline characters. |
| String+Masking |
Hides sensitive information. Returns •••• when self is not empty. |
| String+Split |
Returns the first component of the string up to, but not including, the first occurrence of a given separator. |
Image I/O | CGImagePropertyOrientation+CaseIterable |
Extends CGImagePropertyOrientation to conform to CaseIterable , providing a collection of all orientation cases. |
| CGImagePropertyOrientation+CustomStringConvertible |
Makes CGImagePropertyOrientation instances print-friendly. Examples:- print(orientation.description) Output: Left (Rotated 90° CW (ClockWise) - print(orientation.shortDescription) Output: Up - print(orientation.emoji) Output (orientation is up/mirrored): ⬆️🪞 - print(orientation.emoji) Output (orientation is unknown): 🤷🏻♂️ |
| CGImagePropertyOrientation+UIImage.Orientation |
Facilitates the conversion between CGImagePropertyOrientation and UIImage.Orientation , ensuring accurate mapping despite their differing underlying numeric values. |
PhotoKit | PHAssetMediaSubtype+CustomStringConvertible |
Makes PHAssetMediaSubtype instances print-friendly. Examples:- print(phAssetMediaType.description) Output: photoPanorama - print(phAssetMediaType.description) Output: videoHighFrameRate |
| PHAssetMediaType+CustomStringConvertible |
Makes PHAssetMediaType instances print-friendly. Examples:- print(phAssetMediaType.description) Output: Image - print(phAssetMediaType.description) Output: Audio |
SwiftUI | FadeOut |
Fades out the edge of a view based on a given FadeOut.Edge . |
| FrameSize |
Adds a dashed-colored frame-size container to a view for UI debugging. |
| Shape+RoundedCorner |
Produces a shape with rounded corners. Allows specifying which corner is to be rounded. For example:.cornerRadius(20, corners: [.topLeft, .bottomRight]) |
| StatefulPreviewWrapper |
Makes Xcode's preview canvas fully functional for previewing SwiftUI views that take @Bindings as input. |
| View+Modify |
Allows applying view modifiers based on some criteria. For example:Text("Some").modify { if someCondition { $0.bold() } } |
FadeOut | FrameSize | RoundedCorner |
---|---|---|
Use Xcode's built-in support for SPM.
or...
In your Package.swift
, add Extensions
as a dependency:
dependencies: [
.package(url: "https://github.com/backslash-f/extensions", from: "1.0.0")
]
Associate the dependency with your target:
targets: [
.target(
name: "YourAppName",
dependencies: [
.product(name: "Extensions", package: "extensions")
]
)
]
Run: swift build