Swiftpack.co -  Package - erikfloresq/RickAndMortyAPI
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
erikfloresq/RickAndMortyAPI
Swift wrapper for RickAndMorty API
.package(url: "https://github.com/erikfloresq/RickAndMortyAPI.git", from: "0.0.3")

RickAndMortyAPI

Swift wrapper for RickandMortyAPI I coded this wrapper with combine

Quick look of methods

Character

getCharacter() -> AnyPublisher<ResponseAPI<Character>, Error>

getCharacter(id: String) -> AnyPublisher<Character, Error>

Episode

getEpisode() -> AnyPublisher<ResponseAPI<Episode>, Error>

getEpisode(id: String) -> AnyPublisher<Episode, Error>

Location

getLocation() -> AnyPublisher<ResponseAPI<Location>, Error>

getLocation(id: String) -> AnyPublisher<Location, Error>

Example

class ViewModel: ObservableObject {
    let rickAndMortyAPI = RickAndMortyAPI()
    @Published var characters = [Character](https://raw.github.com/erikfloresq/RickAndMortyAPI/main/)
    var cancellable = Set<AnyCancellable>()

    func getCharacter() {
        rickAndMortyAPI
            .getCharacter()
            .map { $0.results }
            .sink { (completion) in
                print("")
            } receiveValue: { (characters) in
                self.characters = characters
            }.store(in: &cancellable)
    }
}

GitHub

link
Stars: 0
Last commit: 6 days ago

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