All right. 1
So here's the solution. 2
So in this file, we're going to copy this line 3
that is the base you URL for our request. And we're going to put it up here so that we can make it available 4
to all of our methods inside our class. 5
And the next thing I'm going to do is I'm going to write a method. Now, you can call your method whatever 6
you want, but I'm going to call it requestInfo and I'm going to pass in a single parameter that is the 7
flowerName that we got back from our classification model. It's going to be of data type String. 8
And inside here, I'm going to make my Alamofire request. 9
So I've already imported Alamofire and SwiftyJSON, so I should be able to simply write 10
Alamofire.request. And this is almost the one that I want. 11
So the URL I'm going to pass in, this is going to be that Wikipedia URL that we got up there. 12
The method is, of course, a get method and the parameters are going to be the parameters that we got from 13
that text file earlier on. 14
So if I just copy all of these parameters over, then I can paste it in here and I can pass it into here. 15
So it's called parameters. 16
Now, I'm going to modify this template that I got from Alamofire a little bit. 17
I want to get rid of the encoding and the headers. 18
But instead, I'm going to call the completionHandler. 19
So I'm going to write responseJSON 20
and you can see that it suggested to me the one that I want which is the completionHandler. 21
So I'm going to hit enter, then I'm going to select this placeholder and hit enter again. And the data 22
I get back 23
I'm just going to call response, and then inside the closure, I'm going to check to see if the response 24
was successful. 25
So if response.results.isSuccess, then I will 26
print "Got the keep Wikipedia info." And finally, all we need to do is just to print the response into 27
the debug console. 28
All right. 29
So we're always done. 30
One thing to remember is that we haven't actually called this method anyway yet. 31
So I've just realized that our classification isn't actually protected against the cases where our 32
FlowerClassifier doesn't return any result. 33
So let's be safe and use a guard statement to protect those situations. 34
So after we've gotten back our classification identifier, then we're going to pass this in as the 35
flowerName. 36
So that is going to be the title that we're going to pass into the URL. 37
So let's do that once we've successfully gotten back our results. 38
And I'm going to call this method request info. 39
So because we're inside a closure, as denoted by the "in" keyword, then we're going to use "self" in front 40
of all our method calls. 41
So self.request info and the flowerName is going to be classification.identifier. 42
All right. Cool. 43
So that's done, and we're ready for a spin. 44
And you can see down here, we've got "Got the wikipedia info," SUCCESS, and we've got all of this information 45
back from Wikipedia including that extract that we're after. 46
All right. So well done if you manage to get here by yourself. 47
If not or if there's anything confusing, 48
have a look back at the lessons where we covered Alamofire and HTTP requests. 49
And if you're still stuck, then be sure to start a thread in the question-answer section, and we'll try 50
and help you out. In the next lesson, 51
we're going to go in and parse all of this JSON using SwiftyJSON so that we can grab out our extract 52
and display it inside a label. 53
So I'll see you there.