user793789 user793789 -5 years ago 171
Swift Question

Siesta Swift Casting from ImplicitlyUnwrappedOptional<Swift.AnyObject> to Array<AnyObject>

I am configuring ResponseTransformer of siesta to return array of objects.

service.configureTransformer("/models/*") {

but somehow when I try to convert them to back to array using
let objects = response.content as! [Object]
I got this exception
Could not cast value of type 'Swift.ImplicitlyUnwrappedOptional<Swift.AnyObject>' (0x382a0a0) to 'Swift.Array<Object>' (0x16f5358).

Answer Source

You need to map your response, like this

configureTransformer("/models/*") {

And to get later, you can try this way

let objects = resource.typedContent() ?? []
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download