The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey.

Last update: May 7, 2022

QuoteKit Logo

QuoteKit

Twitter Follow

The QuoteKit is a Swift framework to use the free APIs provided by Quotable created by Luke Peavey. It uses the latest async/await syntax for easy access and contains all the APIs like fetching a random quote, all quotes, authors, tags and searching quotes and authors.

Requirements

As it uses the async/await feature of Swift 5.5, the platforms currently supported are iOS 15.0+, macOS 12.0+, watchOS 8.0+ and tvOS 15.0+. There's a PR merged in Swift language related to back deployment, and the framework will be updated accordingly to support the older OSes.

Edit: While waiting and hoping for the backport to happen, the framework now supports iOS 13.0+, macOS 11.0+, watchOS 6.0+ and tvOS 13.0+

Installation

To add QuoteKit in your project, the best way is via the Swift Package Manager.

dependencies: [
    .package(url: "https://github.com/rudrankriyam/QuoteKit.git")
]

Usage

The struct QuoteKit contains static methods you can call for fetching the revelant data. For example, to get the list of quotes -

do {
    var quotes: Quotes?
    quotes = try await QuoteKit.quotes()
} catch {
    print(error)
}

The examples given below are similar to the ones in Quotable's README.

Random Quote

Returns a single random Quote object from the /random API.

var randomQuote: Quote?
randomQuote = try await QuoteKit.randomQuote()

You can customise the request by adding query parameters like minimum and maximum length of the quote or the tag associated with it. You can also get a random quote by a specific author(s).

Few examples:

Random Quote with tags "technology" AND "famous-quotes" -

try await QuoteKit.randomQuote(tags: [.technology, .famousQuotes], type: .all)

Random Quote with tags "History" OR "Civil Rights" -

try await QuoteKit.randomQuote(tags: [.history, .civilRights], type: .either)

Random Quote with a maximum length of 50 characters -

try await QuoteKit.randomQuote(maxLength: 150)

Random Quote with a length between 100 and 140 characters -

try await QuoteKit.randomQuote(minLength: 100, maxLength: 140)

Random Quote by the author "Aesop" and "Stephen Hawking" -

try await QuoteKit.randomQuote(authors: ["aesop", "stephen-hawking"])

List Quotes

Returns the Quotes object based on the given queries from the /quotes API. By default, the list contains 20 Quote in one page.

var quotes: Quotes?
quotes = try await QuoteKit.quotes()

Few examples:

Get all quotes with a maximum length of 50 characters -

try await QuoteKit.quotes(maxLength: 150)

Get all quotes with a length between 100 and 140 characters -

try await QuoteKit.quotes(minLength: 100, maxLength: 140)

Get the first page of quotes, with 20 results per page -

try await QuoteKit.quotes(page: 1)

Get the second page of quotes, with 20 results per page, with a limit of 10 quotes -

try await QuoteKit.quotes(limit: 10, page: 2)

Get all quotes with the tags love OR happiness -

try await QuoteKit.quotes(tags: [.love, .happiness], type: .either)

Get all quotes with the tags technology AND famous-quotes -

try await QuoteKit.quotes(tags: [.technology, .famousQuotes], type: .all)

Get all quotes by author, using the author's slug -

try await QuoteKit.quotes(authors: ["albert-einstein"])

Get all quotes sorted by author -

try await QuoteKit.quotes(sortBy: .author)

Get all quotes sorted by content, in descending order -

try await QuoteKit.quotes(sortBy: .content, order: .descending)

Quote By ID

If there is one, return a single Quote object for the given id from the /quotes/:id API.

var quote: Quote?
quote = try await QuoteKit.quote(id: "2xpHvSOQMD")

List Authors

Returns the Authors object matching the given queries from the /authors API. By default, the list contains 20 Author in one page. You can filter multiple authors by providing their slugs in the query parameter.

var authors: Authors?
authors = try await QuoteKit.authors()

Few examples:

Get the first page of authors, with 20 results per page -

try await QuoteKit.authors(page: 1)

Get the second page of authors, with 20 results per page, with a limit of 10 authors -

try await QuoteKit.authors(limit: 10, page: 2)

Get all authors, sorted alphabetically by name -

try await QuoteKit.authors(sortBy: .name)

Get all authors, sorted by number of quotes in descending order -

try await QuoteKit.authors(sortBy: .quoteCount, order: .descending)

Get a single author by slug -

try await QuoteKit.authors(slugs: ["albert-einstein"])

Get multiple authors by slug -

try await QuoteKit.authors(slugs: ["albert-einstein", "abraham-lincoln"])

Author By ID

If there is one, return a single Author object for the given id from the /authors/:id API.

var author: Author?
author = try await QuoteKit.author(id: "XYxYtSeixS-o")

Author Profile Image URL

Returns the image URL for given author slug. You can specify the image size as well. The default image size is 700x700.

var authorImageURL: URL?
authorImageURL = QuoteKit.authorProfile(size: 1000, slug: "aesop")

List Tags

Returns the Tags object containing the list of all tags from the /tags API. You can sort it and order the sorted results.

var tags: Tags?
tags = try await QuoteKit.tags()

Get all tags, sorted alphabetically by name -

try await QuoteKit.tags(sortBy: .name)

Get all tags, sorted by number of quotes in descending order -

try await QuoteKit.tags(sortBy: .quoteCount, order: .descending)

Search Quotes

Returns the Quotes object based on the search query from the /search/quotes API. By default, the list contains 20 Quote in one page.

var quotes: Quotes?
quotes = try await QuoteKit.searchQuotes(for: "love")

Get the first page of searched quotes, with 20 results per page -

try await QuoteKit.searchQuotes(for: "love", page: 1)

Get the second page of searched quotes, with 20 results per page, with a limit of 10 quotes -

try await QuoteKit.searchQuotes(for: "love", limit: 10, page: 2)

Search Authors

Returns the Authors object based on the search query from the /search/authors API. By default, the list contains 20 Author in one page.

var quotes: Quotes?
quotes = try await QuoteKit.searchAuthors(for: "kalam")

Get the first page of searched authors, with 20 results per page -

try await QuoteKit.searchAuthors(for: "kalam", page: 1)

Get the second page of searched authors, with 20 results per page, with a limit of 10 authors -

try await QuoteKit.searchAuthors(for: "kalam", limit: 10, page: 2)

Data Models

There are many different data models for using this framework.

  • Quote

The object represents a single quote. You can get the content of the quote using the content variable. The tags is an array of the relevant tag associated with the quote. To get the number of characters in the quote, use length.

struct Quote: Decodable, Identifiable {
    var id: String
    var tags: [String]
    var content: String
    var author: String
    var authorSlug: String
    var length: Int
    var dateAdded: String
    var dateModified: String
    
    enum CodingKeys: String, CodingKey {
        case id = "_id"
        case tags, content, author, authorSlug, length, dateAdded, dateModified
    }
}
  • Author

The object represents a single author. You can get the link to their Wikipedia page or their official website using link. bio contains a brief, one paragraph about the author. Use description instead to get a shorter description of the person's occupation or what they're known for. quotes contains an array of the author's quote.

Bool { lhs.id == rhs.id } } ">
struct Author: Decodable, Identifiable {
    var id: String
    var link: String
    var bio: String
    var description: String
    var name: String
    var quoteCount: Int
    var slug: String
    var dateAdded: String
    var dateModified: String
    var quotes: [Quote]?
    
    enum CodingKeys: String, CodingKey {
        case link, bio, description
        case id = "_id"
        case name, quoteCount, slug
        case dateAdded, dateModified
        case quotes
    }
}

extension Author: Equatable {
    static func ==(lhs: Author, rhs: Author) -> Bool {
        lhs.id == rhs.id
    }
}

GitHub

https://github.com/rryam/QuoteKit
You might also like...

🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.

🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.

Model-View-Presenter template A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern. This

Mar 9, 2022

A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

Jan 10, 2022

This is a fully functioning Guess The Flag game I created as part of my 100 days of SwiftUI course with Paul Hudson.

This is a fully functioning Guess The Flag game I created as part of my 100 days of SwiftUI course with Paul Hudson.

GuessTheFlag This is a fully functioning Guess The Flag game that was a part of my 100 days of SwiftUI course with Paul Hudson. In this app my challen

Jan 19, 2022

🏀 iOS and Android NBA app created with React Native

🏀 iOS and Android NBA app created with React Native

Swish An iOS and Android NBA app created with React Native. If you would like to request a feature, find a bug, have a question, or would like to leav

Feb 10, 2022

Are you sure the chemical compounds of your daily use are 100% safe? Use Chem-Aware, identify them right now!

Are you sure the chemical compounds of your daily use are 100% safe? Use Chem-Aware, identify them right now!

View Project On Devpost: Built With: PubChem's REST API How To Install Chem Aware: Prerequiste: Latest Version of Xcode and Simulators installed The a

May 24, 2022

How to use swiftlint to identify unused code or unused imports in a Swift codebase

Swift compilation database This repository demonstrates how to use swiftlint to identify unused code or unused imports in a Swift codebase. How to run

Feb 10, 2022

Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

Apr 8, 2022

A sample app demonstrates how to use Atlantis on Swift Playground (iOS/macOS)

A sample app demonstrates how to use Atlantis on Swift Playground (iOS/macOS)

Atlantis with Swift Playground A sample app demonstrates how to use Atlantis on

Dec 22, 2021

Use this template as a starting point for any Swift 5 module that you want other people to include in their projects

Swift 5 Module Template Use this template as a starting point for any Swift 5 mo

Dec 28, 2021
This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

Jun 5, 2022
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

Jun 27, 2022
Package that extends Combine with some useful APIs

CombineExpanded Package that extends Combine with some useful APIs. New API: then shareReplay Future.deferred then Wait for completion of self, then f

Nov 24, 2021
Free Monads in swift

This repo is based on my blog post on Free Monads in swift.

Nov 15, 2021
A free and open source xkcd comic reader for iOS.
A free and open source xkcd comic reader for iOS.

A free, ad-free, open-source, native, and universal xkcd.com reader for iOS. Download it from the app store now! Architecture AFNetworking for network

Jun 5, 2022
Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

May 22, 2022
Tutorials from sparrowcode.io website. You can add new, translate or fix typos. Also you can add your apps from App Store for free.

Страницы доступны на sparrowcode.io/en & sparrowcode.io/ru Как добавить свое приложение Добавьте элемент в json /ru/apps/apps.json. Если ваше приложен

May 22, 2022
Free and open source manga reader for iOS and iPadOS.

Aidoku A free and open source manga reading application for iOS and iPadOS. Features Ad free Robust WASM source system Online reading through external

Jun 22, 2022
Project 03 I created for "iOS & Swift - The Complete iOS App Development Bootcamp"
Project 03 I created for

Dicee This is the third project I created for "iOS & Swift - The Complete iOS App Development Bootcamp" Our Goal The objective of this tutorial is to

Dec 23, 2021
Spiro - Swift Playgrounds 4 app created on the iPad
Spiro - Swift Playgrounds 4 app created on the iPad

Spiro Swift Playgrounds 4 app created on the iPad^. ^ Xcode also used as explain

Jun 17, 2022