Latest 1.0.0
License MIT
Platforms ios 9.0

Build Status
Carthage compatible


Pack is a tiny wrapper around Encodable/Decodable protocols that let you write code in the same fashion (well, almost) as you would write it using ObjectMapper. ObjectMapper is the main source of inspiration for this library, so you’ll find that some protocols and objects have the same names and structures. It is made so you can easily migrate your existing ObjectMapper code to Pack.


Why would you use this library? In some cases default implementation / code generation of Encodable/Decodable gives you great results and keeps your code as short as possible. However, if you need to slightly customize the process of mapping you’ll write a lot of repetative code like this:

class Item: Codable {
    let userId: String
    let position: Int
    let score: Int

    private enum CodingKeys: String, CodingKey {
        case userId = "id"
        case position
        case score

    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)

        userId = try container.decodeIfPresent(String.self, forKey: .userId) ?? ""
        position = try container.decodeIfPresent(Int.self, forKey: .position) ?? 0
        score = try container.decodeIfPresent(Int.self, forKey: .score) ?? 0

    func encode(to encoder: Encoder) throws {
        let container = try encoder.container(keyedBy: CodingKeys.self)

        try encode(String.self, forKey: .userId)
        try encode(Int.self, forKey: .position)
        try encode(Int.self, forKey: .score)

So istead of that Pack lets you write:

class Item: Mappable {
    var userId = ""
    var position = 0
    var score = 0

    required init() {

    func mapping(map: Map) {
        userId <- map["id"]
        position <- map["position"]
        score <- map["score"]

Since Pack is just a wrapper any class that has implemented Mappable protocol also has compability with code that is using Encodable/Decodable already.



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Pack into your Xcode project using CocoaPods, specify it in your Podfile:


pod 'Pack'

Then, run the following command:

$ pod install


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Pack into your Xcode project using Carthage, specify it in your Cartfile:

github "istered/Pack"

Run carthage update to build the framework and drag the built Pack.framework into your Xcode project.


Anton Romanov


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

Latest podspec

    "name": "Pack",
    "version": "1.0.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "summary": "Pack is a tiny wrapper around Encodable/Decodable protocols.",
    "homepage": "",
    "authors": {
        "Istered": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "platforms": {
        "ios": "9.0"
    "source_files": "Source/**/*.{h,m,swift}",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This