CreateAPI icon indicating copy to clipboard operation
CreateAPI copied to clipboard

Documentation on how to use decoded entity fields

Open jnorris441 opened this issue 1 year ago • 1 comments

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.

jnorris441 avatar Feb 15 '24 18:02 jnorris441

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
            }
        }

jnorris441 avatar Feb 15 '24 20:02 jnorris441