我的实现文件中有一个错误,它一直在标记,我似乎无法修复。我已经注释掉了错误。我该如何解决这个错误?
#import "FilmSearchService.h"
@implementation FilmSearchService
@synthesize searchTerm;
@synthesize delegate;
@synthesize results;
-(void)main {
NSString *api_key = @"1234";
NSString *search_term = [searchTerm stringByAddingPercentEscapeUsingEncoding:NSASCIIStringEncoding]; // no visible @ interface for 'NSString' declares the selector 'stringByAddingPercentEscapeUsingEncoding'
NSString *url = [NSString stringWithFormat:@"http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=%@&q=%@", api_key, search_term];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
if (responseData != nil) {
NSError *error = nil;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
if (error) {
[delegate serviceFinished:self withError:YES];
} else {
results = (NSArray *) [json valueForKey:@"movies"];
[delegate serviceFinished:self withError:NO];
}
} else {
[delegate serviceFinished:self withError:YES];
}
}@end
电影搜索服务头文件:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ServiceDelegate.h"
@interface FilmSearchService : NSOperation
{
NSString *searchTerm;
id<ServiceDelegate> delegate;
NSArray *results;
}
@property (nonatomic, retain) NSString *searchTerm;
@property (nonatomic, retain) id<ServiceDelegate> delegate;
@property (nonatomic, retain) NSArray *results;
@end
如果这是一个相对简单的问题,我很抱歉,我对目标 c 很陌生,希望您能耐心等待。
谢谢你。