Objective-C/CocoaHTTPServer - Is it possible pass how response a NSString object?

439 views Asked by At

I'm using the CocoaHTTPServer in my project and now i need to response to a simple GET request with a string. So i check the incoming parameter and i have created an NSString object with the string that i want return. But i don't know how return this string. Obviously i can't use "return xmlList" because xcode remember to me that the pointer is incompatible. The server want a result type NSObject. How can i do?

- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path{

  HTTPLogTrace();
  if ([path isEqualToString:@"/getPhotos"]){
      NSString *xmlList = [[NSString alloc] init];
      MyServerMethods* myServerMethods = [[MyServerMethods alloc] init];
      xmlList = [myServerMethods getPhotos];
      NSLog(@"RETURN PHOTOS LIST %@", xmlList);
  }

  return nil;

}

Thanks

1

There are 1 answers

0
Hieicker On

Ok, i have resolved my problem in this mode:

if ([path isEqualToString:@"/getPhotos"]){
    NSString *xmlList = [[NSString alloc] init];
    MyServerMethods* myServerMethods = [[MyServerMethods alloc] init]; //First, we create an instance of MyServerMethods
    xmlList = [myServerMethods getPhotos];
    NSData* xmlData = [xmlList dataUsingEncoding:NSUTF8StringEncoding];
    HTTPDataResponse *xmlResponse = [[HTTPDataResponse alloc] initWithData:xmlData];
    return xmlResponse;
}