CreateAPI
CreateAPI copied to clipboard
Documentation on how to use decoded entity fields
I have an entity MediaType that has a .metadata field which is decoded to the entity type MetadataType or String. The type of this field is MediaType.Metadata?. Sounds OK so far.
The example in the documentation doesn't show how to use such an entity field inside a decoded entity.
For example if I now have a decoded MediaType from a request, what can I do with media.metadata which has the type Optional(TestKit.MediaType.Metadata.metadataType(TestKit.MetadataType))
I can't just use the fields inside, like media.metadata?.title
It would be nice if the docs explained how to do this.
The answer seems to be something like this?
var metadata:MetadataType? = nil
if let mediaMetadata = media?.metadata {
switch mediaMetadata {
case .metadataType(let metadataType):
metadata = metadataType
default:
metadata = nil
}
}