I am working on an iOS application using Swift that takes a word from a user and finds the synonyms for that word. It then offers to find the definitions for each of those synonyms.
I have done a lot of research but I have been having trouble finding any simple way to just access a thesaurus or dictionary using Swift and get synonyms or definitions. I am not interested in using the UIReferenceLibraryViewController since Apple is against much use of that and I hope to post my application on the App Store. I am aware that there are some dictionaries out there that are built using Objective-C, but I would be unsure of how to implement those in my (currently) Swift-only application.
I have found one API for Oxford dictionaries here that provides implementation for Swift, but there are a few hurdles (such as pricing and app keys that I don't have yet) that I am unsure about and am therefore curious if there are any other methods out there.
If anyone is aware of a simple way to access a thesaurus or dictionary through Swift to simply get a list of synonyms for a word or a definition of a word, I would greatly appreciate it. If there are no simple ways to do this but there are good instructions for a more complicated way to go about doing this, those would also be appreciated. Thanks!
As you have mentioned 99% of the APIs are paid services or having limited features. But still the one that i would prefer using is
With the basic version of wordsapi (unpaid version) you can make up to 2500 calls / day. I would suggest you to use the same till your app gets some recognition. Later, if you feel your app is about to make more load, you can update to the paid version which makes sense.
Just putting the sample request on how to make the same in swift. Replace the
MapKey
with your
wordsApiKey
let string = "https://wordsapiv1.p.mashape.com/words/stack/synonyms"
let url = NSURL(string: string)
let request = NSMutableURLRequest(URL: url!)
request.setValue("MapKey", forHTTPHeaderField: "X-Mashape-Key")
request.HTTPMethod = "GET"
let session = NSURLSession.sharedSession()
let request = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if let resp = response as? NSHTTPURLResponse {
// Do what you want to do with your response.
}
}
request.resume()
Putting the response that i got for the word "stack" that i tried to search for. (I tried out with curl command to get the response)
{
"word": "stack",
"synonyms": [
"smokestack",
"push-down list",
"push-down stack",
"heap",
"pile",
"push-down storage",
"push-down store",
"batch",
"deal",
"flock",
"good deal",
"great deal",
"hatful",
"lot",
"mass",
"mess",
"mickle",
"mint",
"mountain",
"muckle",
"passel",
"peck",
"plenty",
"pot",
"quite a little",
"raft",
"sight",
"slew",
"spate",
"tidy sum",
"wad"
]
}
There are other features apart from synonyms like antonyms, definition, examples etc., that you can use of it. Hope this one helps.