I'm making a swift app in Xcode that makes use of a cocapod called HNKWordLookup (originally written in objective c). This pod uses the WordNik API to return a random word. My only issue is that a lot of the words that are returned are quite obscure.
I figured that I could go to the http://developer.wordnik.com/docs page and set parameters there, and then be given a Request URL that caters to these parameters . I assume I need to put this into my code somewhere in place of another URL that is present within the pre written pod, but I have no clue where to put the request URL. At first I put it in place in the following line of code which was located in the pod's .m file ("HNKLookup.m:):
static NSString *const kHNKLookupBaseUrl = @"http://api.wordnik.com:80/v4";
changing it to
static NSString *const kHNKLookupBaseUrl = @"http://api.wordnik.com:80/v4/words.json/randomWord?hasDictionaryDef=true&excludePartOfSpeech=definite-article&minCorpusCount=1&maxCorpusCount=-1&minDictionaryCount=30&maxDictionaryCount=-1&minLength=1&maxLength=-1&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5";
but this broke my code. Is there a certain phrase or area that I should be looking out for within the pod where I can put my new request URL in and thus run my program with my desired parameters? As you can tell I'm pretty new to programming.
You should not change kHNKLookupBaseUrl in pod. kHNKLookupBaseUrl is used to connect to the service. Use this to get a random word:
[[HNKLookup sharedInstance] randomWordWithCompletion:^(NSString *randomWord, NSError *error) {
if (error) {
NSLog(@"ERROR: %@", error);
} else {
NSLog(@"%@", randomWord);
}
}];
You have the parameters initialised in HNKHttpSessionManager.m
+ (NSUInteger)randomWordWithCompletion:(void (^)(NSURLSessionDataTask *, id,
NSError *))completion
{
return
[self startRequestWithPath:kHNKPathRandomWord
parameters:@{
@"hasDictionaryDef" :
@(kHNKRandomWordShouldHaveDictionaryDefinition),
@"minCorpusCount" : @(kHNKRandomWordMinimumCorpusCount),
@"maxCorpusCount" : @(kHNKRandomWordMaximumCorpusCount),
@"minDictionaryCount" :
@(kHNKRandomWordMinimumDictionaryCount),
@"maxDictionaryCount" :
@(kHNKRandomWordMaximumDictionaryCount),
@"minLength" : @(kHNKRandomWordMinimumLength),
@"maxLength" : @(kHNKRandomWordMaximumLength)
}
completion:completion];
}
You can tweak this to get desired result.