skip to Main Content

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


  1. 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];
    
    Login or Signup to reply.
  2.     NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString 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]]];
    

    You were missing a step, NSURL does not have a method called stringWithFormat.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search