A collection of useful Swift extensions to simplify and enhance iOS, macOS, watchOS, tvOS, and visionOS development. Each extension is crafted to save development time and improve code readability and reusability.
- Features
- Installation
- Requirements
- Usage
- Extension List
- Migration Guides
- Communication
- Contributing
- Open Radars
- FAQs
- Credits
- Donations
- License
- Core Extensions: Add functionality to common Swift types such as
String,Array,Date,Dictionary, and more. - UIKit Extensions: Simplify common UI tasks with extensions for
UIView,UIColor,UIImage, etc. - Foundation Extensions: Convenient methods for
URL,DateFormatter,Data, and other Foundation types. - Lightweight and Modular: Include only the extensions you need, easy to keep your project lightweight.
- Modern Swift Support: Designed for Swift 5.7 and above, leveraging the latest language features.
To install using Swift Package Manager, add the following line to your Package.swift file:
dependencies: [
.package(url: "https://github.com/mjn2max/swift-extensions.git", from: "1.0.0")
]Then import in your source files:
import SwiftExtensions- Download or clone the repository.
- Copy the Sources/SwiftExtensions folder into your Xcode project.
- Use the extensions as you would any other Swift code.
| Platform | Minimum Swift Version | Installation | Status |
|---|---|---|---|
| iOS 13.0+ | 5.7.1 / Xcode 14.1 | Swift Package Manager, Manual | Not Fully Tested |
| macOS 13.0+ | Latest Only | Swift Package Manager | Not Fully Tested |
| watchOS | Latest Only | Swift Package Manager | Not Fully Tested |
| tvOS | Latest Only | Swift Package Manager | Not Fully Tested |
| visionOS | Latest Only | Swift Package Manager | Not Fully Tested |
Swift-Extensions aims for “drop-in” convenience. Just import and use the new methods and computed properties:
Example 1: Rounding a Double
let value = 3.14159
let rounded = value.rounded(toPlaces: 2) // 3.14Example 2: String Trimming
let text = " Hello World "
let trimmed = text.trimmed() // "Hello World"Example 3: UIView Corner Radius
let view = UIView()
view.roundCorners(radius: 10)More examples can be found in the Extension List.
Here are some of the most popular extensions in this package:
Double.swift
- rounded(toPlaces:): Round a double to a specified number of decimal places.
- degreesToRadians/radiansToDegrees: Easy angle conversion.
String.swift
- trimmed(): Trims whitespace and newlines.
- isNumeric: Checks if the string contains only numbers.
Array.swift
- unique(): Removes duplicate elements.
For a full list, browse the Sources directory.
The repository’s source folder structure is organized by category, following those in Apple’s Foundation documentation.
Coming soon...
- Bugs & Feature Requests: Please open an issue on GitHub.
- Questions & Support: Use the issue tracker for all questions, suggestions, and support requests.
- Contact: For all communication, please use the GitHub issue tracker to ensure transparency and faster responses.
Contributions are welcome! Please:
- Open an issue or discussion to propose changes or extensions.
- Fork the repo and create your feature branch.
- Add tests for new functionality.
- Submit a pull request with a clear description.
All contributions must follow the Code of Conduct.
If you discover any Swift or Apple bugs that impact this project, please share the radar number and a brief description in this section to help other contributors stay informed.
Q: Can I use only a subset of the extensions?
A: Yes! Just include the specific files you need.
Q: Is this production ready?
A: Core extensions are stable, but some platforms are not fully tested. Use at your discretion and report any issues.
Created and maintained by mjn2max and contributors. See the Contributors page for a full list.
If you find this useful, you can sponsor this project via GitHub Sponsors or Buy Me a Coffee. Your support helps maintain and improve Swift-Extensions!
This project is licensed under the MIT License. See LICENSE for details.