-4

Also don't understand why the downvotes

So the following code is saying it has no member of episode which is correct because the JSON gets passed to PodEpisode first. Then need to pass it to the last subarray

struct PodPost: Codable {
    var programs: [PodEpisode]
}

struct PodEpisode: Codable {
    var episode : [PodProgram]
}

struct PodProgram: Codable, Identifiable {
    let id = UUID()
    var title : String
    var enclosureurl : String
    var summary : String
}

I am calling it via

func getPodcast(podurl:String,completion: @escaping ([PodProgram]) -> ()) {
     
     
       let podurl = podurl
    
        guard let url = URL(string: "https://api.drn1.com.au/api-access/programs/\(podurl)") else { return }
           
           URLSession.shared.dataTask(with: url) { (data, _, _) in
               // Based on the updated structs, you would no
               // longer be decoding an array
               let podcast = try! JSONDecoder().decode(PodPost.self, from: data!)
            
                
               DispatchQueue.main.async{
                   // The array is stored under programs now
                completion(podcast.episode). // THIS IS THE LINE THAT ERROR SHOWS (Value of type 'PodPost' has no member 'episode' )
               }
               
           }
   }

I have tried the following

adding a

let episode = podcast.programs
then using that to call episode.episode // With no success.

Pic of error

enter image description here

RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • 1
    Why did you delete your previous question just to post it again? And is it so hard to figure out how to solve this given the help I gave you in the comments in that deleted question? – Joakim Danielson Aug 22 '20 at 09:18

1 Answers1

-2
let podcast = try! JSONDecoder().decode(PodPost.self, from: data!)

Would give you an object of PodEpisode with property as programs

Now in the completion block you are trying to call podcast.programs.episode which isn't possible as its an array

If you need an episode you would need to do something like this

let episode = podcast.programs.first!.episode

Harish
  • 368
  • 2
  • 10
  • what if I need to return all the epsiodes as they will get put in a list view - Also just updated the question with a pic of the error. – RussellHarrower Aug 22 '20 at 01:14