SuperSimpleMapper 0.1.1

SuperSimpleMapper 0.1.1

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released最后发布2017年4月
SwiftSwift 版本3.0
SPM支持 SPM

FrogRain 维护。



  • FrogRain

SuperSimpleMapper

描述

SuperSimpleMapper 只是一个简单地将一个类型的对象映射到另一个类型的对象的实用工具。如果您在使用 ORM 并且需要将 ORM 对象映射到普通对象以避免复杂对象污染应用程序的所有层次,这将非常有用。它还可以作为 JSON 映射器使用,但在此目的上有许多更好的解决方案。

用法

要运行示例项目,请首先克隆仓库,然后在 Example 目录中运行 pod install

需求

没有特殊要求

安装

SuperSimpleMapper 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中

pod "SuperSimpleMapper"

用法

一个简单的对象

给定此对象

import Foundation

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

在您的应用程序中定义一个位置来放置所有映射。您可以定义所需的所有映射。在这种情况下,在 CoreDataExample 和 Example 对象之间

import Foundation

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

…在您的映射层

import Foundation

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

请查看单元测试类以了解其他用例

作者

FrogRain,email protected

许可证

SuperSimpleMapper 基于 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。