Skip to content

ModelRocket 1.2

Compare
Choose a tag to compare
@jlandon jlandon released this 27 Oct 02:52
· 23 commits to master since this release

Added

  • hasValue and hasKey to JSON (replaces isNil). The behavior of isNil was not always clear, in cases where the JSON contained a valid key but a null value. hasValue and hasKey clears this up.
let json: JSON = [
   "string" : NSNull()
]

json["string"].hasValue   // false
json["string"].hasKey     // true

Fixed

  • Issue where subclassing a Model subclass resulted in broken JSONTransformable conformance.
let json: JSON = [
    "cars" : [
        [
            "model" : "BMW",
            "year" : 2015,
            "number_of_doors" : 4
        ]
    ]
]

class Vehicle: Model, JSONTransformable {
    let model = Property<String>(key: "model")
    let year = Property<Int>(key: "year")
}

class Car: Vehicle {
    let numberOfDoors = Property<Int>(key: "number_of_doors")
}

class Garage: Model {
    let cars = PropertyArray<Car>(key: "cars")
}

let garage = Garage(json: json)

// previously
garage.cars.first   // nil

// now
garage.cars.first   // valid Car object