Model to Dictionary in Swift.
- iOS 10.0+
- Swift 4.0+
struct Person: DictionaryReflectable {
let name: String
let age: Int
let stature: Int
}
let person = Person(name: "liuchang", age: 30, stature: 175)
let dict = person.reflectToDictionary()
print(dict) // ["age": 30, "name": "liuchang", "stature": 175]To integrate Reflect into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'Reflect'- Download everything in the Reflect folder;
- Add (drag and drop) the source files in Reflect to your project.
Reflect is provided under the MIT license. See LICENSE file for details.