adamayoung / TMDb

The Movie Database Swift Package
https://adamayoung.github.io/TMDb/documentation/tmdb
Apache License 2.0
109 stars 28 forks source link

Search All Result Parsing #39

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hey!

Just wanted to start by saying I appreciate this library! I was actually making all the requests I needed myself, but once I ran into this, I figured I could switch over as this seems like a much better implementation than what I had going. I just had a question regarding using the search feature.

My specific use case requires searching movies and shows simultaneously by using the searchAll(..) method within SearchService. This seems to give a mix of results from TMDb with a generic media type.

I'm trying to figure out how I can decipher whether the Media that gets returned in the MediaPageableList is a Movie or TVShow. Even just knowing whether the ID property in Media is for a Movie or TVShow would suffice.

Is there any way to currently do this? Am I possible approaching this incorrectly or missing something? I would appreciate any help or insight on this!

P.S. I want to avoid searching movies and shows separately since the TMDb endpoint for searching all will return a list of content for what's more relevant whether that's movies, shows, or even people.

ghost commented 2 years ago

I also wanted to add as a general note, that I'm essentially looking for 3 pieces of information in the search results. Even some direction as to whether I could do this myself would be appreciated!

adamayoung commented 2 years ago

Hi ghost. Thanks for the feedback!

Regarding the MediaPageableList, when you're iterating through the results, each element is a Media enum. Therefore you could do something like:

switch media {
case .movie(let movie):
   // It's a movie!

case .tvShow(let tvShow):
   // It's a TV Show

case .person(let person):
   // It's a Person
}