A powerful Swift library providing comprehensive extensions for standard Swift types and Foundation/UIKit classes, designed to enhance developer productivity and simplify common programming tasks.
π€ String Extensions
| Category | Features |
|---|---|
| Encoding/Decoding | β’ Base64 encoding/decoding β’ URL encoding/decoding β’ UTF-8 encoding/decoding |
| Text Manipulation | β’ Case transformations (camelCase, snake_case, kebab-case) β’ Trimming whitespace β’ Padding β’ Truncating β’ Removing HTML tags β’ String reversal |
| Validation | β’ URL validation β’ Hexadecimal validation β’ Custom character set validation |
| Formatting | β’ Currency formatting β’ Percentage formatting β’ Number formatting |
| Generation | β’ Random string generation (alphanumeric, alphabetic, numeric) |
| Hashing | β’ SHA1 β’ SHA256 |
π’ Number Extensions
| Category | Features |
|---|---|
| Mathematical Operations | β’ Power calculation β’ Square root β’ Rounding and formatting |
| Utilities | β’ Range clamping β’ Random number generation β’ Type conversions |
| Formatting | β’ Currency formatting β’ Time interval conversions |
π Date Extensions
| Feature | Description |
|---|---|
| Calculations | β’ Time difference calculations β’ Date manipulation (adding/subtracting days) |
| Comparison | β’ isTodayβ’ isInPastβ’ isInFuture |
| Formatting | β’ String conversion with custom formats |
π Collection Extensions
| Feature | Description |
|---|---|
| Safety | β’ Safe subscript access |
| Manipulation | β’ Array chunking β’ Duplicate removal β’ Element swapping β’ Element moving |
β‘ Optional Extensions
| Feature | Description |
|---|---|
| Unwrapping | β’ Convenience unwrapping methods β’ Nil coalescing with default values |
| Utilities | β’ Optional chaining helpers β’ Nil-or-empty checking for collections |
π Property Wrappers
| Wrapper | Description |
|---|---|
| @Clamped | Value range restriction |
| @KeyValueStorage | UserDefaults persistence |
| @Limited | Collection/String length limiting |
| @Masked | String pattern masking |
| @Trimming | Automatic whitespace trimming |
| @Validated | Value validation |
Add Wing to your Package.swift file:
dependencies: [
.package(url: "https://github.com/annurdien/Wing.git", from: "1.0.0")
]import Wing
// Base64 encoding/decoding
let encoded = "Hello".base64Encoded // "SGVsbG8="
let decoded = encoded?.base64Decoded // "Hello"
// Case transformations
"helloWorld".snakeCased // "hello_world"
"hello-world".camelCased // "helloWorld"
"hello world".kebabCased // "hello-world"
// String validation
"https://example.com".isValidURL // true
"FF00FF".isHexadecimal // true
// String manipulation
" Hello World ".trimmed // "Hello World"
"Hello".padding(toLength: 10, withPad: "*") // "Hello*****"
"Hello World".truncate(length: 8) // "Hello..."import Wing
// Mathematical operations
5.squared // 25
16.squareRoot() // 4.0
2.power(3) // 8
// Formatting
123.456.formatted(withFractionDigits: 2) // "123.46"
1234.currencyFormatted(locale: Locale(identifier: "en_US")) // "$1,234.00"
// Time intervals
5.minutes // TimeInterval(300)
2.hours // TimeInterval(7200)import Wing
let date = Date()
date.isToday // true
date.isInPast // false
date.isInFuture // false
// Date formatting
date.toString("yyyy-MM-dd") // "2025-04-21"
date.toString(dateStyle: .full, timeStyle: .short) // "Sunday, April 21, 2025 at 10:30 AM"
// Date manipulation
date.addingDays(7) // Date one week from now
date.days(from: Date()) // 0import Wing
// Safe subscript access
let array = ["a", "b", "c"]
array[safe: 1] // Optional("b")
array[safe: 5] // nil
// Array manipulation
let numbers = [1, 2, 2, 3, 3, 3]
numbers.removingDuplicates() // [1, 2, 3]
numbers.chunked(into: 2) // [[1, 2], [2, 3], [3, 3]]
var mutableArray = ["a", "b", "c"]
mutableArray.move(from: 0, to: 2) // ["b", "c", "a"]import Wing
let optionalValue: String? = "Hello"
let nilValue: String? = nil
// Convenient unwrapping
optionalValue.ifPresent { value in
print(value) // "Hello"
}
// Default values
nilValue.or("Default") // "Default"
// Optional mapping
optionalValue.mapIfPresent { $0.uppercased() } // Optional("HELLO")import Wing
class Configuration {
@Clamped(min: 0, max: 100)
var volume: Int = 50 // Will always be between 0 and 100
@KeyValueStorage("username")
var username: String = "default" // Persisted in UserDefaults
@Limited(maxLength: 10)
var shortText: String = "" // Will be truncated if longer than 10 characters
@Trimming
var userInput: String = "" // Whitespace will be automatically trimmed
}- iOS 15.0+
- Swift 6.0+
- Xcode 15.0+
# Generate documentation using DocC
xcodebuild docbuild -scheme Wing -destination generic/platform=iOS
# View in Xcode
Product > Build Documentation (β + β§ + D)Visit our online documentation for detailed API references and guides.
We welcome contributions! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
Annurdien Rasyid
- GitHub: @annurdien
- Twitter: @annurdien
Made with β€οΈ by Annurdien Rasyid
