0
我正在关注Jon Reid的video。我遵循了他的所有代码,直到遇到错误。我不知道在哪里定义了ResourceFetcher
,为什么这不适合我!下面是代码:什么是ResourceFetcher在模拟Objective-C中的对象?
在视图控制器:
-(void) fetchResources
{
NSString *string = [NSString stringWithFormat:@"%@weather.php?format=json", BaseURLString];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:string
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"%@",(NSDictionary *)responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Error in retrieve data");
}
];
}
在MockAFNetworkingGET:
@implementation MockAFNetworkingGET
-(AFHTTPRequestOperation *) GET : (NSString*) URLString
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation * operation, id respondObject)) success
failure:(void (^)(AFHTTPRequestOperation * operation, NSError *error))failure
{
self.callCount += 1;
self.URLString = URLString;
self.parameters = parameters;
self.success = success;
self.failure = failure;
return self.fakeReturnValue;
}
@end
在ResourceFetcherTests:
#import <XCTest/XCTest.h>
#import "MockAFNetworkingGET.h"
#import "ViewController.h"
@interface ResourceFetcherTests : XCTestCase
@end
@implementation ResourceFetcherTests
-(void) testFetchResources_shouldCallGet
{
id mockGet = [[MockAFNetworkingGET alloc]init];
ResourceFetcher *sut = [[ResourceFetcher alloc] initWithGETManager:mockGet];
//ResourceFetcher is not existing and giving me compiler error!!
}
@end
我有复制和教程贴在这里的所有代码。这里不知道ResourceFetcher
。我谷歌,但没有出现!它是一个库中的内部结构还是我需要在某处定义它或导入某个库?
这里是链接到幻灯片: