wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
264 stars 109 forks source link

Array of custom type in resource definition #185

Open yahyaalshaar opened 7 years ago

yahyaalshaar commented 7 years ago

It seems that I can't tell spine for custom object type in attribute definition since it will crash at run time so I make definition "any"

In my case I have an array of "WorkingHourAttribute" if I keep this type definition the app will crash: '*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Example.BranchResource 0x600000195880> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key workingHours.''

`class BranchResource: Resource {

var workingHours: [Any]? // I want => workingHours: [WorkingHourAttribute]?
override class var fields: [Field] {
    return fieldsFromDictionary([
        "workingHours": WorkingHourAttribute().serializeAs("working-hours")
        ])
}`

how to write array definition in resource class with custom object attribute Thanks in advance