MagicMapper alternatives and similar libraries
Based on the "JSON" category.
Alternatively, view MagicMapper alternatives based on common mentions on social networks and blogs.
-
MJExtension
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file. -
SBJson
This framework implements a strict JSON parser and generator in Objective-C. -
HandyJSON
A handy swift json-object serialization/deserialization library -
AlamofireObjectMapper
An Alamofire extension which converts JSON response data into swift objects using ObjectMapper -
FlatBuffersSwift
This project brings FlatBuffers (an efficient cross platform serialization library) to Swift. -
Motis
Easy JSON to NSObject mapping using Cocoa's key value coding (KVC) -
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding. -
JAYSON
๐งฑ A JSON decoding/encoding library that handles optimistically or strictly. -
Mappable
flexible JSON to Model converter, specially optimized for immutable properties -
WAMapping
A library to turn dictionary into object and vice versa for iOS. Designed for speed! -
NSTEasyJSON
The better way to deal with JSON in Objective-C (inspired by SwiftyJSON) -
GuardedSwiftyJSON
Swift guarded model initializers for SwiftyJSON -
Alter
Alter is framework to make mapping Codable property and key easier.
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of MagicMapper or a related project?
README
magic-mapper-swift
๐ Super light and easy automatic JSON to model mapper
- [ ] Finish writing
README.md
- [ ] Ability to map
NSManagedObject
- [x] Ability to convert model back to dictionary
How to setup
Step 1: Get the JSON model
{
"total_count": 176552,
"incomplete_results": false,
"items": [
{...}
]
}
Step 2: Write the Swift models
class GithubRepository: NSObject, Mappable {
var id : String = ""
var name : String = ""
var body : String = ""
var url : String = ""
var photo : String = ""
var createdAt : Date?
}
class GithubSearch: NSObject, Mappable {
var total : Int = 0
var items : [GithubRepository] = []
}
Step 3: Link your custom namings with the JSON model
The mapFromDictionary
property lets you customize the properties mappings. You can also access nested values within dictionaries and arrays (example: emails.0.address
).
var mapFromDictionary: [String : String] {
return [
"body" : "description",
"photo" : "owner.avatar_url",
"createdAt" : "created_at"
]
}
Step 4: Custom properties
The mapFromDictionaryTypes
property let's you customize the type of the JSON property (only for optionals). If you have other Swift structures that you need to use, just extend them using the Mappable
protocol.
var mapFromDictionaryTypes: [String : Mappable.Type] {
return [
"createdAt" : Date.self
]
}
For instance createdAt
is of type Date
and the JSON property is of type String
. In order to convert the String
to a Date
type, just extend it using the Mappable
protocol and it will automatically know to convert and set the value to the model.
extension Date: Mappable {
init?(from: Any) {
if let value = from as? String {
let formatter = DateFormatter()
formatter.dateFormat = "YYYY-MM-dd'T'HH':'mm':'ss'Z'"
if let date = formatter.date(from: value) {
self.init(timeIntervalSince1970: date.timeIntervalSince1970)
return
}
}
self.init()
}
}
And that's it!
You can now populate your model from the generic dictionary that comes from your network layer. Happy coding :)
Alamofire.request(APIURL).responseJSON { (response) in
if let dictionary = response.result.value as? KeyValue {
self.feed = GithubSearch(dictionary)
}
}
Contributing
There's still work to do here! Our goal is to speed up development times, making JSON mapping easy as 1-2-3. We would love to see you involved in this project!