0

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.

4

1 回答 1

2

您不应更改 pod 中的 kHNKLookupBaseUrl。kHNKLookupBaseUrl 用于连接到服务。使用它来获得一个随机单词:

    [[HNKLookup sharedInstance] randomWordWithCompletion:^(NSString *randomWord, NSError *error) {
    if (error) {
        NSLog(@"ERROR: %@", error);
    } else {
        NSLog(@"%@", randomWord);
    }
}];

您在 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];
}

您可以调整它以获得所需的结果。

于 2018-02-24T12:24:29.150 回答