Closed alak closed 8 years ago
This should be possible using a custom attribute type and matching formatter. It depends on how you want to represent the nested data in your client. It should be something like this:
class LocationAttribute: Attribute {}
struct LocationValueFormatter: ValueFormatter {
func unformat(value: AnyObject, attribute: LocationAttribute) -> AnyObject {
// Convert from serialised form to deserialised form
}
func format(value: AnyObject, attribute: LocationAttribute) -> AnyObject {
// Convert from deserialised form to serialised form
}
}
spine.registerValueFormatter(LocationValueFormatter())
Thanks, perfect
Cool, let me know if there's any trouble :).
@wvteijlingen I'm trying something like this but it's not working.
Let's say in this case I'm creating a custom Object "Location" with all the properties from location node in the json.
Then when I declare the type of location it's "Location" so when you define unformat it's returning an object "Location" and when defining format the parameter is type "Location" and returns String.
I'm getting a message:
this class is not key value coding-compliant for the key location
@Alak Did this work for you?
I think I fixed it, by declaring the property as AnyObject, the problem is when you want to use the property you have to unwrap it as the type you need.
What kind of type is Location
?
Location should be a custom Class called Location that contains all the properties of the location node in the Json file.
I could fix this, the only issue is that is not letting me declare that as a Location property in my Resource Object, I need to declare it as AnyObject, otherwise I get:
this class is not key value coding-compliant for the key location
Hey,
I'm wondering if there is a way to parse subobject in attributes like :
Thanks