TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2016 |
SPMSupports SPM | ✗ |
Maintained by Dan Pourhadi.
SuperSerial uses Swift's Mirror to automatically infer a struct's stored variables, allowing for hassle-free out-of-the-box JSON serialization. Conforming that struct to AutoSerializable allows for easy deserialization as well.
Also supports custom serialization for structs and object types.
See header comments for more details.
struct Person {
let name:String
let age:Int
}
extension Person:AutoSerializable {
init?(withValuesForKeys: [String : Serializable]) {
self.name = withValuesForKeys["name"] as! String
self.age = withValuesForKeys["age"] as! Int
}
}
let people:[Serializable] = [Person(name: "Bob", age: 30), Person(name: "Lisa", age: 32), Person(name: "Mark", age: 29)]
Specify the types that can be serialized and deserialized:
SuperSerial.serializableTypes = [Person.self]
Serialize and deserialize:
let serialized = Serialized(fromArray: people)
let jsonString = serialized.toString()
let fromString = Serialized(serializedString: jsonString)
let deserialized = fromString?.deserialize()
SuperSerial is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SuperSerial"
Daniel Pourhadi, [email protected]
SuperSerial is available under the MIT license. See the LICENSE file for more info.