Latest 0.0.1
Homepage https://github.com/jordanhamill/SwiftyJSONMilk
License MIT
Platforms ios 8.0, osx 10.10, requires ARC
Dependencies Milk, SwiftyJSON
Authors

A SwiftyJSON wrapper that implements Milk Serializer.

Note: Milk requires Swift 2.0 as it uses protocol extensions to provide default implementations of common methods.

Example


struct Person {
    let name: String
    let age: Int
    let weight: Float

    init(age: Int, name: String, height: weight) {
        self.age = age
        self.name = name
        self.weight = weight
    }
}

extension Person: Serializable {
    private init?(name: String?, age: Int?, weight: Float?) {
        if let name = name, age = age, weight = weight {
            self.age = age
            self.name = name
            self.weight = weight
        } else {
            return nil
        }
    }

    func serialize(serializer: Serializer) {
        serializer["age"] <- age
        serializer["name"] <- name
        serializer["weight"] <- weight
    }

    static func deserialize(deserializer: Serializer) -> Patient? {
        return Person(name:   <-deserializer["name"],
                      age:    <-deserializer["age"],
                      weight: <-deserializer["weight"])
    }
}
let jsonSerializer: Serializer = JSONSerializer()
let person: Person = Person(name: "Matt", age: 12, weight: 71.2)
person.serialize(jsonSerializer)

if let jsonString = jsonSerializer.json.rawString() {
    print(jsonString)
    // {
    //    "name": "Matt",
    //    "age": 12,
    //    "weight": 71.2
    // }
}

Latest podspec

{
    "name": "SwiftyJSONMilk",
    "version": "0.0.1",
    "summary": "A SwiftyJSON wrapper that implements Milk Serializer.",
    "homepage": "https://github.com/jordanhamill/SwiftyJSONMilk",
    "license": "MIT",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "authors": {
        "Jordan Hamill": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jordanhamill/SwiftyJSONMilk.git",
        "tag": "0.0.1"
    },
    "source_files": "SwiftyJSONMilk/**/*.{h,m,swift}",
    "requires_arc": true,
    "dependencies": {
        "Milk": [
            "0.0.2"
        ],
        "SwiftyJSON": []
    }
}

Pin It on Pinterest

Share This