Skip to content

mjn2max/swift-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift-Extensions

Swift Platforms Swift Package Manager

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.

Table of Contents

Features

  • 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.

Installation

Swift Package Manager

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

Manual Integration

  • Download or clone the repository.
  • Copy the Sources/SwiftExtensions folder into your Xcode project.
  • Use the extensions as you would any other Swift code.

Requirements

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

Usage

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.14

Example 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.

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.

Migration Guides

Coming soon...

Communication

  • 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.

Contributing

Contributions are welcome! Please:

  1. Open an issue or discussion to propose changes or extensions.
  2. Fork the repo and create your feature branch.
  3. Add tests for new functionality.
  4. Submit a pull request with a clear description.

All contributions must follow the Code of Conduct.

Open Radars

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.

FAQs

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.

Credits

Created and maintained by mjn2max and contributors. See the Contributors page for a full list.

Donations

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!

License

This project is licensed under the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages