Encoding / decoding an Array of structs

Peter Hudson

Hi All

I’m trying to encode / decode an Array of struct.
The struct in question is itself Codable - and the compiler is happy with it.

In the following code,  roles is an Array of struct called Scene…

try container.encode(roles, forKey: .roles)  

  and the compiler complains    ! Reference to member 'roles' cannot be resolved without a contextual type

roles  = try container.decode([SceneRole].self, forKey: .roles)

   and the compiler complains    !  Ambiguous reference to member 'decode(_:forKey:)

Any suggestions gratefully received !