I’m attempting to ping eBay’s API using an HTTP request, however Xcode is giving me the following error
No known class method for selector stringWithFormat
What I want to do here is append whatever string is input in the searchField to the end of the url. What am I doing wrong? Appreciate any help!
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.nextButton) return;
if (self.searchField.text.length > 0) {
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL stringWithFormat:@"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=***APP ID ****&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=3&itemFilter(2).paramName=Currency&itemFilter(2).paramValue=USD&itemFilter(3).name=ListingType&itemFilter(3).value=FixedPrice&keywords=%@", self.searchField.text]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
}
2
Answers
You first need to create a
NSString
containing the URL and then create anNSURL
out of it.You were missing a step, NSURL does not have a method called stringWithFormat.