Search code examples
iosobjective-cjsonebay-api

Pinging eBay API throws stringWithFormat error


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

}

Solution

  • You first need to create a NSString containing the URL and then create an NSURL out of it.

    NSString *urlString = [NSString stringWithFormat:@"http://example.com/",
        self.searchField.text];
    NSURL *url = [NSURL URLWithString:urlString];