SuperSimpleMapper 0.1.1

SuperSimpleMapper 0.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by FrogRain.



  • By
  • FrogRain

SuperSimpleMapper

Description

SuperSimpleMapper is just a simple utility to map object of one type to object of another type. Useful if you are using an ORM and feel the need to map to plain objects your ORM objects to prevent complex objects polluting all layers of your app. It also works as json mapper but there’s lot’s of better solutions for that purpose. .

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

No special requirements

Installation

SuperSimpleMapper is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SuperSimpleMapper"

Usage

A simple object

Given this object:

import Foundation

class CoreDataExample {
    var title:String?
    var text:String?
}
class Example {
    var exampleTitle:String?
    var textContent:String?
}

Define a location in your app to put all mappings. You can define as many as you need. In this case between CoreDataExample and Example object:

import Foundation

Mapper.createMap { (complexExample: CoreDataExample) -> Example in
    let example = Example()
    example.exampleTitle = complexExample.title
    example.textContent = complexExample.text
    return example
}

…In your mapping layer

import Foundation

if let result = Mapper.map(source: ComplextComment()) as Comment? {
    //mission complete!!!
}

Take a look at Unit Test classes to figure out other use cases

Author

FrogRain, [email protected]

License

SuperSimpleMapper is available under the MIT license. See the LICENSE file for more info.