David Caunt

Himotoki Tutorial

Himotoki is a simple yet powerful library for decoding JSON. From the project page:

Himotoki (紐解き) is a type-safe JSON decoding library purely written in Swift. This library is highly inspired by popular JSON parsing libraries in Swift: Argo and ObjectMapper.

This article provides a brief tutorial and Xcode Playground to help learn how to use it. You can clone the Playground from GitHub here.

 Basic Decoding

As you can see from the Himotoki README, creating a model and specifying how to decode it from JSON is fairly straightforward:

struct Group: Decodable {
    let name: String
    let floor: Int
    let locationName: String
    let optional: [String]?

    // MARK: Decodable

    static func decode(e: Extractor) throws -> Group {
        return try Group(
            name: e <| "name",
            floor: e <| "floor",
            locationName: e <| [ "location", "name" ], // Parse

Continue reading →

Subscribe to David Caunt

Don’t worry; we hate spam with a passion.
You can unsubscribe with one click.