Hi,
I'm working on an app that generates Radom movies. I know that it's not possible with your API; to bypass that the app generates random numbers, then cross references that with the id's from movies. Via this methode it works, I don't know how to filter it with popular movies yet, but it works.
The issue is: I can't get the movie posters, genre and other stuff with it. Only the titels appear. Any idea what I'm doing wrong?
I'm using swiftUI btw:
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(movieTitles.indices, id: \.self) { index in
Text(movieTitles[index])
.font(.headline)
.padding()
}
}
}
Button(action: {
var randomIds = [Int]()
while randomIds.count < 3 {
let randomId = Int.random(in: 1...803322)
if !randomIds.contains(randomId) {
randomIds.append(randomId)
}
}
MovieStore.shared.fetchMovies(from: .popular) { result in
switch result {
case .success(let response):
var movies = response.results
var titles = [String]()
for id in randomIds {
if let movie = movies.first(where: { $0.id == id }) {
titles.append(movie.title)
movies.removeAll(where: { $0.id == movie.id })
}
}
self.movieTitles = titles
self.movies = movies
case .failure(let error):
print(error.localizedDescription)
}
}
}) {
Text("Get 3 Random Movies")
.font(.headline)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
Spacer()
ForEach(movieTitles.indices, id: \.self) { index in
HStack {
MoviePosterCard(movie: movies[index], imageLoader: ImageLoader())
.frame(width: 100, height: 60)
.onAppear {
self.imageLoader.loadImage(with: self.movies[index].posterURL)
}
Text(movieTitles[index])
}
}
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by ticao2 š§š· pt-BR
on May 8, 2023 at 11:33 AM
What I do know is that when I make an API Request for Popular movies,
https://developers.themoviedb.org/3/movies/get-popular-movies
I get the following information on each of the movies: