You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide helps you get started with string and date conversion features in SwiftDevKit.
3
+
Learn how to use SwiftDevKit's powerful features for text processing, time utilities, and data conversion.
4
4
5
5
## Overview
6
6
7
-
SwiftDevKit provides simple and type-safe ways to convert values to and from strings, including specialized support for date formatting with thread safety.
7
+
SwiftDevKit provides a comprehensive set of tools for common development tasks, including string manipulation, time handling, and various data conversion utilities.
let color =try ColorConversion.from(hex: "#FF8000")
81
+
let rgbComponents = color.rgbComponents
82
+
```
83
+
84
+
## Number Formatting
81
85
82
-
### Thread Safety
86
+
```swift
87
+
let number =1234567.89
88
+
let formatted = number.format(style: .currency,
89
+
locale: Locale(identifier: "en_US"))
90
+
// "$1,234,567.89"
83
91
84
-
All date conversion operations are thread-safe and can be called concurrently from multiple tasks. The framework uses an actor-based formatter cache to ensure optimal performance while maintaining thread safety.
92
+
let scientific = number.format(style: .scientific)
93
+
// "1.23E6"
94
+
```
85
95
86
96
## Error Handling
87
97
88
98
Handle conversion errors appropriately:
89
99
90
100
```swift
91
101
do {
92
-
let value =tryawaitInt.fromString("not a number")
93
-
} catchlet error asStringConversionError {
94
-
switch error {
95
-
case .invalidInput(let value):
96
-
print("Invalid input: \(value)")
97
-
}
102
+
let color =try ColorConversion.from(hex: "invalid")
103
+
} catchlet error asColorConversionError {
104
+
print("Invalid color format: \(error.localizedDescription)")
98
105
}
99
106
100
107
do {
101
-
let date =tryawait Date.fromString("invalid", format: DateFormat.iso8601)
102
-
} catchlet error asDateConversionError {
103
-
switch error {
104
-
case .invalidFormat(let value):
105
-
print("Invalid date format: \(value)")
106
-
case .invalidComponents:
107
-
print("Invalid date components")
108
-
case .invalidFormatString(let format):
109
-
print("Invalid format string: \(format)")
110
-
case .custom(let message):
111
-
print(message)
112
-
}
108
+
let time =try TimeZoneUtilities.convert(date: Date(),
109
+
from: "Invalid/Zone",
110
+
to: "UTC")
111
+
} catchlet error asTimeZoneError {
112
+
print("Time zone error: \(error.localizedDescription)")
113
113
}
114
114
```
115
115
116
116
## Next Steps
117
117
118
-
- Explore the API documentation for more details
118
+
- Explore the API documentation for detailed information
119
119
- Check out example projects in the repository
120
120
- Join our community discussions
121
121
122
-
For more information, visit the [SwiftDevKit Documentation](https://github.com/yourusername/SwiftDevKit).
122
+
For more information, visit the [SwiftDevKit Documentation](https://github.com/owdax/SwiftDevKit).
0 commit comments