A Datamuse API Swift wrapper without external depedencies and support for async/await.
- iOS 15+ / macOS 12+ / tvOS 15+ / watchOS 8+
- Xcode 15.0+
To integrate datamuse-swift
into your Xcode project, open your project settings, navigate to the "Package Dependencies" section, and add the following URL:
https://github.com/ezefranca/datamuse-swift.git
Add the following to your Podfile
:
platform :ios, '15.0'
use_frameworks!
pod 'datamuse-swift', '~> 1.0.0'
Run the following command to install the dependency:
$ pod install
Clone the repository and drag the Sources
folder into your Xcode project.
First, import the library:
import datamuse_swift
Create an instance of DataMuseClient
:
let client = DataMuseClient()
Use the fetchWords
method with any of the predefined endpoints.
Task {
do {
let words = try await client.fetchWords(endpoint: .similarWords(to: "ring"))
words.forEach { print($0.word) }
} catch {
print("Error: \(error.localizedDescription)")
}
}
The following endpoints are available:
Description | Method |
---|---|
Words with a meaning similar to a given word | .similarWords(to: String) |
Words related to a word that start with a specific letter | .wordsRelated(to: String, startingWith: String) |
Words related to a word that end with a specific letter | .wordsEndingWith(to: String, endingWith: String) |
Words spelled similarly to a given word | .wordsSpelledLike(String) |
Words that rhyme with a given word | .wordsThatRhyme(with: String) |
Words that rhyme with a given word and are related | .wordsThatRhymeWithRelated(with: String, related: String) |
Adjectives often used to describe a word | .adjectivesOftenUsed(toDescribe: String) |
Adjectives describing a word sorted by related topics | .adjectivesDescribing(this: String, related: String) |
Nouns often described by a given adjective | .nounsOftenDescribed(byAdjective: String) |
Words that often follow another word in a sentence | .wordsThatFollow(following: String, startingWith: String) |
Words triggered by (strongly associated with) another word | .wordsTriggered(by: String) |
Suggestions based on partial input | .suggestions(for: String) |
Words that start, finish, and have a specific pattern | .wordWithPattern(start: String, finish: String, lettersBetween: Int) |
All API responses return an array of Word
objects:
public struct Word: Codable {
public let word: String
public let score: Int?
}
datamuse-swift
is released under the MIT license. See LICENSE for details.