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
。我谷歌,但沒有出現!它是一個庫中的內部結構還是我需要在某處定義它或導入某個庫?
這裏是鏈接到幻燈片: