TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Mar 2016 |
SPMSupports SPM | ✗ |
Maintained by Matthew Lui.
Dictionify want to solve the needs of convert objects to dictionary with simple step. By using Dictionify, you don’t have to write boring code for each class like
dictionary["myPropertyA"] = self.myPropertyA
dictionary["myPropertyB"] = self.myPropertyB
. . .
(or by overriding decode/encode(withCoder))
When you subclass Dictionify, and tag your property with “dynamic”, you gain the power of calling toDictionary() to get your dictionary that contain all properties in your class. Also, we allow you to init a object with dictionary. Even more, Dictionify can recorgnize properties in dictionary those are also Dictionify subclass(Included in an Array),instantiate them and put right back in. For example:
class Person :Dictionify {
dynamic var name :String
dynamic var likedBook :[Book]
init(name:String){
self.name = name
likedBook = []
}
}
class Book :Dictionify{
dynamic var name :String
dynamic var content :String
}
var ben = Person(name:Ben)
var book = Book("I love",content:"Bla Bla Bla...")
ben.likedBook = [book]
var benDict = ben.toDictionary(withClassName: true) /// when with class name, Dictionify can instantiate archived property with proper class.
var anotherBen = Person(benDict)
var anotherBook = anotherBen.likedBook.first
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 9.0
Dictionify is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Dictionify"
matthewlui, [email protected]
Dictionify is available under the MIT license. See the LICENSE file for more info.