A lightweight Swift package providing handy type conversion utilities for Int, Double, Float, String, and Date.
Designed for iOS and iPadOS using Swift Package Manager.
- 🔄 Simple one-liner conversions:
Int↔Double↔Float↔String
- 📆 String ↔ Date parsing & formatting
- Optional (
Date?) and throwing (throws) APIs
- Optional (
- ⚡ Optimized with
@inlinablefor cross-module performance - 📦 Distributed as a Swift Package (SPM)
-
Open your project in Xcode.
-
Go to File → Add Packages…
-
Enter the repo URL:
https://github.com/rqbctg/convertible.git -
Choose Dependency Rule → “Up to Next Major” from
1.0.0. -
Select the target you want to add the package to.
dependencies: [
.package(url: "https://github.com/rqbctg/convertible.git", from: "1.0.0")
],
targets: [
.target(
name: "MyApp",
dependencies: [
.product(name: "ConvertibleUtils", package: "ConvertibleUtils")
]
)
]import ConvertibleUtils
// MARK: - Number Conversions
let n: Int = 42
print(n.toDouble) // 42.0
print(n.toString) // "42"
print(n.toFloat) // 42.0
let d: Double = 3.14
print(d.toInt) // 3
print(d.toString) // "3.14"
print(d.toFloat) // 3.14
let f: Float = 12.75
print(f.toInt) // 12
print(f.toString) // "12.75"
print(f.toDouble) // 12.75
// MARK: - String Conversions
print("123".toInt) // Optional(123)
print("abc".toIntValue) // 0
print("3.14".toDouble) // 3.14
print("nan".toFloatValue) // 0.0 (safe fallback)
// MARK: - Date Parsing
let dateStr = "2025-08-26 12:34:56"
let parsed = dateStr.parseDate() // Date?
let parsedThrow = try? dateStr.parseDate() // throws on failure
// MARK: - Date Formatting
let now = Date()
print(now.toString()) // "2025-08-26 12:34:56"
print(now.toString(format: "yyyy/MM/dd")) // "2025/08/26"All functions are covered with XCTest.
Run the test suite:
swift testSample test:
func testInt_toDouble() {
XCTAssertEqual(42.toDouble, 42.0, accuracy: 0.0001)
}ConvertibleUtils is available under the MIT license.
See LICENSE for details.
Pull requests are welcome!
- For major changes, open an issue first to discuss your idea.
- Make sure tests pass (
swift test) before submitting. - Please update documentation/README where appropriate.
- Add support for
Decimalconversions - Locale-aware number parsing/formatting
- More robust date parsing (multiple formats, ISO8601, RFC3339)
- Additional math & string helpers
Coming soon — demo iOS project using ConvertibleUtils.