Description
This is an open-source library that allows you to generate Swift code based on your custom data structures. It provides a powerful way to automatically generate the CustomStringConvertible
and CustomDebugStringConvertible
implementations for your structs or classes.
Installation
You can easily install ReflectedStringConvertible using CocoaPods
. Just add the following line to your Podfile:
pod 'ReflectedStringConvertible'
Then, run the following command in your terminal:
pod install
Usage
To use ReflectedStringConvertible, simply follow these steps:
- Import the
ReflectedStringConvertible
module: - Make your struct or class conform to the
ReflectedStringConvertible
protocol - Optionally, you can override the
description
anddebugDescription
computed properties if needed
Here’s an example:
// Import the module
import ReflectedStringConvertible
// Make your struct conform to ReflectedStringConvertible
struct Person: ReflectedStringConvertible {
let name: String
let age: Int
}
// Create an instance of Person
let john = Person(name: "John", age: 30)
// Print the description
print(john.description)
// Output: "Person(name: John, age: 30)"
Advanced Usage
Here are some advanced features provided by ReflectedStringConvertible:
- Type Exclusion: You can exclude certain properties from the reflection using the
shouldReflectProperty(_:)
method. - Nested Types: The library also supports reflecting nested classes or structs.
- Custom Reflection: You can provide custom reflection for types that do not conform to
CustomStringConvertible
.
For more details and examples, please refer to the GitHub repository.
Requirements
ReflectedStringConvertible requires:
- iOS 8.0+
- macOS 10.9+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 11.0+
License
ReflectedStringConvertible is available under the MIT license. See the LICENSE file for more info.