Swiftpack.co - adamayoung/TMDb as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
adamayoung/TMDb
The Movie Database Swift Package
.package(url: "https://github.com/adamayoung/TMDb.git", from: "5.0.0")

TMDb - The Movie Database

CI Coverage Quality Gate Status Security Rating

Swift Package Manager compatible platforms

A Swift Package for The Movie Database (TMDb) https://www.themoviedb.org

Requirements

  • Swift 5.2+

async/await

  • Swift 5.5

Installation

Swift Package Manager

Add the TMDb package as a dependency to your Package.swift file, and add it as a dependency to your target.

// swift-tools-version:5.2

import PackageDescription

let package = Package(
  name: "MyProject",
  dependencies: [
    .package(url: "https://github.com/adamayoung/TMDb.git", upToNextMajor: "5.0.0")
  ],
  targets: [
    .target(name: "MyProject", dependencies: ["TMDb"])
  ]
)

Setup

Get an API Key

Create an API Key from The Movie Database web site https://www.themoviedb.org/documentation/api.

Set you API Key

Set your API key before making any calls

TMDbAPI.setAPIKey("ahb4334n43nj34jk43nklkg4")

API Areas

Certifications

Get an up to date list of the officially supported movie certifications on TMDB.

Configuration

System wide configuration information.

Discover

Discover movies by different types of data like average rating, number of votes, genres and certifications.

Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates.

Movies

Get information about movies.

People

Get information about people.

Search

Search for movies, TV shows and people.

Trending

Get the daily or weekly trending items. The daily trending list tracks items over the period of a day while items have a 24 hour half life. The weekly list tracks items over a 7 day period, with a 7 day half life.

TV Shows

Get information about TV shows.

TV Show Seasons

Get information about TV show seasons.

Examples

// Set API Key
TMDbAPI.setAPIKey("ahb4334n43nj34jk43nklkg4")

Discover Movies

let discoverService = TMDb.shared.discover

// With a completion handler
discoverService.fetchMovies { result in
    let movies = (try? result.get())?.results
    ...
}

// With Combine
discoverService.moviesPublisher()
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.movies, on: self)
    .store(in: &cancellables)

// With async/await
let movieList = try await discoverService.movies()
let movies = movieList.results

Trending TV Shows this week, 2nd page

let trendingService = TMDb.shared.trending

// With a completion handler
trendingService.fetchTVShows(inTimeWindow: .week, page: 2) { result in
    let tvShows = (try? result.get())?.results
    ...
}

// With Combine
trendingService.tvShowsPublisher(inTimeWindow: .week, page: 2)
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.tvShows, on: self)
    .store(in: &cancellables)

// With async/await
let tvShowList = try await trendingService.tvShows(inTimeWindow: .week, page: 2)
let tvShows = list.results

Popular People

let personService = TMDb.shared.person

// With a completion handler
personService.fetchPopular { result in
    let people = (try? result.get())?.results
    ...
}

// With Combine
personService.popularPublisher()
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.people, on: self)
    .store(in: &cancellables)

// With async/await
let personList = try await personService.popular()
let people = personList.results

References

GitHub

link
Stars: 4
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

5.0.0
15 weeks ago
  • Added support for Swift 5.5's async/await
  • Added documentation to the models

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics