annurdien/Wing
Collection of native Swift extensions and property wrappers
π Table of Contents
β¨ Features
<details open> <summary>π€ String Extensions</summary>
| Category | Features | |----------|----------| | Encoding/Decoding | β’ Base64 encoding/decoding<br>β’ URL encoding/decoding<br>β’ UTF-8 encoding/decoding | | Text Manipulation | β’ Case transformations (camelCase, snake_case, kebab-case)<br>β’ Trimming whitespace<br>β’ Padding<br>β’ Truncating<br>β’ Removing HTML tags<br>β’ String reversal | | Validation | β’ URL validation<br>β’ Hexadecimal validation<br>β’ Custom character set validation | | Formatting | β’ Currency formatting<br>β’ Percentage formatting<br>β’ Number formatting | | Generation | β’ Random string generation (alphanumeric, alphabetic, numeric) | | Hashing | β’ SHA1<br>β’ SHA256 |
</details>
<details> <summary>π’ Number Extensions</summary>
| Category | Features | |----------|----------| | Mathematical Operations | β’ Power calculation<br>β’ Square root<br>β’ Rounding and formatting | | Utilities | β’ Range clamping<br>β’ Random number generation<br>β’ Type conversions | | Formatting | β’ Currency formatting<br>β’ Time interval conversions |
</details>
<details> <summary>π Date Extensions</summary>
| Feature | Description | |---------|-------------| | Calculations | β’ Time difference calculations<br>β’ Date manipulation (adding/subtracting days) | | Comparison | β’ isToday<br>β’ isInPast<br>β’ isInFuture | | Formatting | β’ String conversion with custom formats |
</details>
<details> <summary>π Collection Extensions</summary>
| Feature | Description | |---------|-------------| | Safety | β’ Safe subscript access | | Manipulation | β’ Array chunking<br>β’ Duplicate removal<br>β’ Element swapping<br>β’ Element moving |
</details>
<details> <summary>β‘ Optional Extensions</summary>
| Feature | Description | |---------|-------------| | Unwrapping | β’ Convenience unwrapping methods<br>β’ Nil coalescing with default values | | Utilities | β’ Optional chaining helpers<br>β’ Nil-or-empty checking for collections |
</details>
<details> <summary>π Property Wrappers</summary>
| 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 |
</details>
π¦ Installation
Swift Package Manager
Add Wing to your Package.swift file:
dependencies: [
.package(url: "https://github.com/annurdien/Wing.git", from: "1.0.0")
]π Usage Examples
String Extensions
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..."Number Extensions
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)Date Extensions
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()) // 0Collection Extensions
import 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"]Optional Extensions
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")Property Wrappers
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
}βοΈ Requirements
- iOS 15.0+
- Swift 6.0+
- Xcode 15.0+
π Documentation
Building Documentation
xcodebuild docbuild -scheme Wing -destination generic/platform=iOS
# View in Xcode
Product > Build Documentation (β + β§ + D)Online Documentation
Visit our online documentation for detailed API references and guides.
π₯ Contributing
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.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
Package Metadata
Repository: annurdien/Wing
Homepage: https://annurdien.github.io/Wing/documentation/wing
Stars: 1
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: ios, macos, package, property-wrapper, swift, swift-extensions
README: README.md