зеркало из https://github.com/github/OHHTTPStubs.git
- Generating a static library libOHHTTPStubs easy to include in your application projects (thus avoiding to mess with your own application files in your project)
- Simplifying example project (which is now iOS5+ only, but the OHHTTPStubs library is still iOS4+ compatible)
This commit is contained in:
Родитель
3900ded4b7
Коммит
5ccf37a794
|
@ -8,8 +8,6 @@ build/*
|
|||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
*.xcworkspace
|
||||
!default.xcworkspace
|
||||
xcuserdata
|
||||
profile
|
||||
*.moved-aside
|
||||
|
|
|
@ -0,0 +1,239 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
0979357D161B6251006DB5D5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0979357C161B6251006DB5D5 /* Foundation.framework */; };
|
||||
0979359B161B62C0006DB5D5 /* OHHTTPStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = 09793598161B62C0006DB5D5 /* OHHTTPStubs.m */; };
|
||||
0979359C161B62C0006DB5D5 /* OHHTTPStubsResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 0979359A161B62C0006DB5D5 /* OHHTTPStubsResponse.m */; };
|
||||
0979359E161B62EF006DB5D5 /* OHHTTPStubs.h in Headers */ = {isa = PBXBuildFile; fileRef = 09793597161B62C0006DB5D5 /* OHHTTPStubs.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
0979359F161B62EF006DB5D5 /* OHHTTPStubsResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 09793599161B62C0006DB5D5 /* OHHTTPStubsResponse.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
09793579161B6251006DB5D5 /* libOHHTTPStubs.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOHHTTPStubs.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0979357C161B6251006DB5D5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
09793597161B62C0006DB5D5 /* OHHTTPStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OHHTTPStubs.h; sourceTree = "<group>"; };
|
||||
09793598161B62C0006DB5D5 /* OHHTTPStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHHTTPStubs.m; sourceTree = "<group>"; };
|
||||
09793599161B62C0006DB5D5 /* OHHTTPStubsResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OHHTTPStubsResponse.h; sourceTree = "<group>"; };
|
||||
0979359A161B62C0006DB5D5 /* OHHTTPStubsResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHHTTPStubsResponse.m; sourceTree = "<group>"; };
|
||||
097935A0161B644E006DB5D5 /* PortableLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = PortableLibrary.xcconfig; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
09793576161B6251006DB5D5 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
0979357D161B6251006DB5D5 /* Foundation.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
0979356E161B6251006DB5D5 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
097935A0161B644E006DB5D5 /* PortableLibrary.xcconfig */,
|
||||
0979357E161B6251006DB5D5 /* OHHTTPStubs */,
|
||||
0979357B161B6251006DB5D5 /* Frameworks */,
|
||||
0979357A161B6251006DB5D5 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0979357A161B6251006DB5D5 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
09793579161B6251006DB5D5 /* libOHHTTPStubs.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0979357B161B6251006DB5D5 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0979357C161B6251006DB5D5 /* Foundation.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0979357E161B6251006DB5D5 /* OHHTTPStubs */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
09793597161B62C0006DB5D5 /* OHHTTPStubs.h */,
|
||||
09793598161B62C0006DB5D5 /* OHHTTPStubs.m */,
|
||||
09793599161B62C0006DB5D5 /* OHHTTPStubsResponse.h */,
|
||||
0979359A161B62C0006DB5D5 /* OHHTTPStubsResponse.m */,
|
||||
);
|
||||
name = OHHTTPStubs;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
0979359D161B62EA006DB5D5 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
0979359E161B62EF006DB5D5 /* OHHTTPStubs.h in Headers */,
|
||||
0979359F161B62EF006DB5D5 /* OHHTTPStubsResponse.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
09793578161B6251006DB5D5 /* OHHTTPStubs */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 09793587161B6251006DB5D5 /* Build configuration list for PBXNativeTarget "OHHTTPStubs" */;
|
||||
buildPhases = (
|
||||
09793575161B6251006DB5D5 /* Sources */,
|
||||
09793576161B6251006DB5D5 /* Frameworks */,
|
||||
0979359D161B62EA006DB5D5 /* Headers */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = OHHTTPStubs;
|
||||
productName = OHHTTPStubs;
|
||||
productReference = 09793579161B6251006DB5D5 /* libOHHTTPStubs.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
09793570161B6251006DB5D5 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0450;
|
||||
ORGANIZATIONNAME = AliSoftware;
|
||||
};
|
||||
buildConfigurationList = 09793573161B6251006DB5D5 /* Build configuration list for PBXProject "OHHTTPStubs" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = 0979356E161B6251006DB5D5;
|
||||
productRefGroup = 0979357A161B6251006DB5D5 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
09793578161B6251006DB5D5 /* OHHTTPStubs */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
09793575161B6251006DB5D5 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
0979359B161B62C0006DB5D5 /* OHHTTPStubs.m in Sources */,
|
||||
0979359C161B62C0006DB5D5 /* OHHTTPStubsResponse.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
09793585161B6251006DB5D5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
09793586161B6251006DB5D5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
|
||||
SDKROOT = iphoneos;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
09793588161B6251006DB5D5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 097935A0161B644E006DB5D5 /* PortableLibrary.xcconfig */;
|
||||
buildSettings = {
|
||||
DSTROOT = /tmp/OHHTTPStubs.dst;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
09793589161B6251006DB5D5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 097935A0161B644E006DB5D5 /* PortableLibrary.xcconfig */;
|
||||
buildSettings = {
|
||||
DSTROOT = /tmp/OHHTTPStubs.dst;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = NO;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
09793573161B6251006DB5D5 /* Build configuration list for PBXProject "OHHTTPStubs" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
09793585161B6251006DB5D5 /* Debug */,
|
||||
09793586161B6251006DB5D5 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
09793587161B6251006DB5D5 /* Build configuration list for PBXNativeTarget "OHHTTPStubs" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
09793588161B6251006DB5D5 /* Debug */,
|
||||
09793589161B6251006DB5D5 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 09793570161B6251006DB5D5 /* Project object */;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// PortableLibrary.xcconfig
|
||||
// http://mrox.net/blog/2011/06/19/framework-like-static-libraries/
|
||||
//
|
||||
// Global configuration settings to generate a portable static library that will
|
||||
// - Compile gracefully in both Build and in Archive processes
|
||||
// - Reduce at its maximum the integration in the client application
|
||||
//
|
||||
// To integrate the library in your client application
|
||||
// - Add the library xcodeproj to your application's workspace
|
||||
// - Add the library to the "Link Binary With Libraries" section of the "Build Phase" tab of your application project
|
||||
// - use #import <LibraryName/Header.h> in your client files
|
||||
//
|
||||
|
||||
PUBLIC_HEADERS_FOLDER_PATH = include/$(PROJECT_NAME)
|
||||
INSTALL_PATH = /../BuildProductsPath/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/
|
||||
OTHER_LDFLAGS = -ObjC
|
||||
|
||||
// NOTE: be sure to configure SKIP_INSTALL to YES in Debug and NO in Release in this library project
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "container:OHHTTPStubsDemo/OHHTTPStubsDemo.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "container:OHHTTPStubs/OHHTTPStubs.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -7,49 +7,23 @@
|
|||
//
|
||||
|
||||
#import "MainViewController.h"
|
||||
#import "OHHTTPStubs.h"
|
||||
|
||||
@interface MainViewController(/* Private Interface */) {
|
||||
dispatch_queue_t downloadQueue;
|
||||
}
|
||||
- (void)configureStubs;
|
||||
@end
|
||||
|
||||
|
||||
#import <OHHTTPStubs/OHHTTPStubs.h>
|
||||
|
||||
|
||||
@implementation MainViewController
|
||||
// IBOutlets
|
||||
@synthesize delaySwitch = _delaySwitch;
|
||||
@synthesize textView = _textView;
|
||||
@synthesize installTextStubSwitch = _installTextStubSwitch;
|
||||
@synthesize installImageStubSwitch = _installImageStubSwitch;
|
||||
@synthesize imageView = _imageView;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Private Methods
|
||||
|
||||
- (void)configureStubs
|
||||
{
|
||||
[self installTextStub:self.installTextStubSwitch];
|
||||
[self installImageStub:self.installImageStubSwitch];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Init & Dealloc
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
self = [super initWithCoder:aDecoder];
|
||||
if (self)
|
||||
{
|
||||
downloadQueue = dispatch_queue_create("OHHTTPStubs.example.download", NULL);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
dispatch_release(downloadQueue);
|
||||
#if ! __has_feature(objc_arc)
|
||||
[_textView release];
|
||||
[_imageView release];
|
||||
|
@ -63,7 +37,9 @@
|
|||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self configureStubs];
|
||||
|
||||
[self installTextStub:self.installTextStubSwitch];
|
||||
[self installImageStub:self.installImageStubSwitch];
|
||||
}
|
||||
- (void)viewDidUnload
|
||||
{
|
||||
|
@ -74,7 +50,7 @@
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Actions
|
||||
#pragma mark - Global stubs activation
|
||||
|
||||
- (IBAction)toggleStubs:(UISwitch *)sender
|
||||
{
|
||||
|
@ -86,45 +62,54 @@
|
|||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Text Download and Stub
|
||||
|
||||
|
||||
- (IBAction)downloadText:(UIButton*)sender
|
||||
{
|
||||
NSString* urlString = @"http://www.loremipsum.de/downloads/version3.txt";
|
||||
// Quick & Dirty way to download data without bothering with delegate implementation and such (and compatible with iOS <5.0)
|
||||
sender.enabled = NO;
|
||||
dispatch_async(downloadQueue, ^{
|
||||
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
NSData* downloadedData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
sender.enabled = YES;
|
||||
NSString* receivedText = [[NSString alloc] initWithData:downloadedData encoding:NSASCIIStringEncoding];
|
||||
self.textView.text = receivedText;
|
||||
|
||||
NSString* urlString = @"http://www.loremipsum.de/downloads/version3.txt";
|
||||
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
|
||||
// This is a very handy way to send an asynchronous method, but only available in iOS5+
|
||||
[NSURLConnection sendAsynchronousRequest:req queue:nil completionHandler:^(NSURLResponse* resp, NSData* data, NSError* error)
|
||||
{
|
||||
sender.enabled = YES;
|
||||
NSString* receivedText = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
self.textView.text = receivedText;
|
||||
#if ! __has_feature(objc_arc)
|
||||
[receivedText autorelease];
|
||||
[receivedText release];
|
||||
#endif
|
||||
});
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (IBAction)installTextStub:(UISwitch *)sender
|
||||
{
|
||||
static id textHandler = nil;
|
||||
static id textHandler = nil; // Note: no need to retain this value, it is retained by the OHHTTPStubs itself already :)
|
||||
|
||||
if (sender.on)
|
||||
{
|
||||
// Install
|
||||
textHandler = [OHHTTPStubs addRequestHandler:^OHHTTPStubsResponse *(NSURLRequest *request, BOOL onlyCheck)
|
||||
{
|
||||
NSString* ext = request.URL.absoluteString.pathExtension;
|
||||
if ([ext isEqualToString:@"txt"])
|
||||
{
|
||||
return [OHHTTPStubsResponse responseWithFile:@"stub.txt"
|
||||
contentType:@"text/plain"
|
||||
responseTime:self.delaySwitch.on ? 2.f: 0.f];
|
||||
}
|
||||
else
|
||||
{
|
||||
return OHHTTPStubsResponseDontUseStub;
|
||||
}
|
||||
}];
|
||||
{
|
||||
NSString* ext = request.URL.absoluteString.pathExtension;
|
||||
if ([ext isEqualToString:@"txt"])
|
||||
{
|
||||
return [OHHTTPStubsResponse responseWithFile:@"stub.txt"
|
||||
contentType:@"text/plain"
|
||||
responseTime:self.delaySwitch.on ? 2.f: 0.f];
|
||||
}
|
||||
else
|
||||
{
|
||||
return OHHTTPStubsResponseDontUseStub;
|
||||
}
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -134,25 +119,27 @@
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Image Download and Stub
|
||||
|
||||
- (IBAction)downloadImage:(UIButton*)sender
|
||||
{
|
||||
NSString* urlString = @"http://images.apple.com/iphone/ios/images/ios_business_2x.jpg";
|
||||
// Quick & Dirty way to download data without bothering with delegate implementation and such (and compatible with iOS <5.0)
|
||||
sender.enabled = NO;
|
||||
dispatch_async(downloadQueue, ^{
|
||||
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
NSData* downloadedData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
sender.enabled = YES;
|
||||
self.imageView.image = [UIImage imageWithData:downloadedData];
|
||||
});
|
||||
});
|
||||
|
||||
NSString* urlString = @"http://images.apple.com/iphone/ios/images/ios_business_2x.jpg";
|
||||
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
|
||||
// This is a very handy way to send an asynchronous method, but only available in iOS5+
|
||||
[NSURLConnection sendAsynchronousRequest:req queue:nil completionHandler:^(NSURLResponse* resp, NSData* data, NSError* error)
|
||||
{
|
||||
sender.enabled = YES;
|
||||
self.imageView.image = [UIImage imageWithData:data];
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)installImageStub:(UISwitch *)sender
|
||||
{
|
||||
static id imageHandler = nil;
|
||||
static id imageHandler = nil; // Note: no need to retain this value, it is retained by the OHHTTPStubs itself already :)
|
||||
if (sender.on)
|
||||
{
|
||||
// Install
|
||||
|
@ -178,6 +165,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - Cleaning
|
||||
|
||||
- (IBAction)clearResults
|
||||
{
|
||||
self.textView.text = @"";
|
|
@ -7,19 +7,19 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
097935A2161B654E006DB5D5 /* libOHHTTPStubs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 097935A1161B654E006DB5D5 /* libOHHTTPStubs.a */; };
|
||||
098FBDD415D704E800623941 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 098FBDD315D704E800623941 /* UIKit.framework */; };
|
||||
098FBDD615D704E800623941 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 098FBDD515D704E800623941 /* Foundation.framework */; };
|
||||
098FBDD815D704E800623941 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 098FBDD715D704E800623941 /* CoreGraphics.framework */; };
|
||||
098FBDE015D704E800623941 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 098FBDDF15D704E800623941 /* main.m */; };
|
||||
098FBDED15D7056200623941 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 098FBDEB15D7056200623941 /* MainViewController.m */; };
|
||||
098FBDEE15D7056200623941 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 098FBDEC15D7056200623941 /* MainViewController.xib */; };
|
||||
098FBDF415D705E900623941 /* OHHTTPStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = 098FBDF115D705E900623941 /* OHHTTPStubs.m */; };
|
||||
098FBDF515D705E900623941 /* OHHTTPStubsResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 098FBDF315D705E900623941 /* OHHTTPStubsResponse.m */; };
|
||||
098FBDF815D70E2600623941 /* stub.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 098FBDF615D70E2600623941 /* stub.jpg */; };
|
||||
098FBDF915D70E2600623941 /* stub.txt in Resources */ = {isa = PBXBuildFile; fileRef = 098FBDF715D70E2600623941 /* stub.txt */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
097935A1161B654E006DB5D5 /* libOHHTTPStubs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOHHTTPStubs.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
098FBDCF15D704E800623941 /* OHHTTPStubsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OHHTTPStubsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
098FBDD315D704E800623941 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||
098FBDD515D704E800623941 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
|
@ -30,10 +30,6 @@
|
|||
098FBDEA15D7056200623941 /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = "<group>"; };
|
||||
098FBDEB15D7056200623941 /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = "<group>"; };
|
||||
098FBDEC15D7056200623941 /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = "<group>"; };
|
||||
098FBDF015D705E900623941 /* OHHTTPStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OHHTTPStubs.h; sourceTree = "<group>"; };
|
||||
098FBDF115D705E900623941 /* OHHTTPStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHHTTPStubs.m; sourceTree = "<group>"; };
|
||||
098FBDF215D705E900623941 /* OHHTTPStubsResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OHHTTPStubsResponse.h; sourceTree = "<group>"; };
|
||||
098FBDF315D705E900623941 /* OHHTTPStubsResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHHTTPStubsResponse.m; sourceTree = "<group>"; };
|
||||
098FBDF615D70E2600623941 /* stub.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = stub.jpg; sourceTree = "<group>"; };
|
||||
098FBDF715D70E2600623941 /* stub.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = stub.txt; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
@ -43,6 +39,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
097935A2161B654E006DB5D5 /* libOHHTTPStubs.a in Frameworks */,
|
||||
098FBDD415D704E800623941 /* UIKit.framework in Frameworks */,
|
||||
098FBDD615D704E800623941 /* Foundation.framework in Frameworks */,
|
||||
098FBDD815D704E800623941 /* CoreGraphics.framework in Frameworks */,
|
||||
|
@ -55,7 +52,6 @@
|
|||
098FBDC415D704E800623941 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
098FBDEF15D705E900623941 /* OHHTTPStubs */,
|
||||
098FBDD915D704E800623941 /* OHHTTPStubsDemo */,
|
||||
098FBDD215D704E800623941 /* Frameworks */,
|
||||
098FBDD015D704E800623941 /* Products */,
|
||||
|
@ -86,10 +82,10 @@
|
|||
098FBDEA15D7056200623941 /* MainViewController.h */,
|
||||
098FBDEB15D7056200623941 /* MainViewController.m */,
|
||||
098FBDEC15D7056200623941 /* MainViewController.xib */,
|
||||
098FBDFA15D70E2F00623941 /* Stub Data */,
|
||||
098FBDFA15D70E2F00623941 /* Stubs */,
|
||||
098FBDDA15D704E800623941 /* Supporting Files */,
|
||||
);
|
||||
path = OHHTTPStubsDemo;
|
||||
name = OHHTTPStubsDemo;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
098FBDDA15D704E800623941 /* Supporting Files */ = {
|
||||
|
@ -102,25 +98,14 @@
|
|||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
098FBDEF15D705E900623941 /* OHHTTPStubs */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
098FBDF015D705E900623941 /* OHHTTPStubs.h */,
|
||||
098FBDF115D705E900623941 /* OHHTTPStubs.m */,
|
||||
098FBDF215D705E900623941 /* OHHTTPStubsResponse.h */,
|
||||
098FBDF315D705E900623941 /* OHHTTPStubsResponse.m */,
|
||||
);
|
||||
name = OHHTTPStubs;
|
||||
path = ../OHHTTPStubs;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
098FBDFA15D70E2F00623941 /* Stub Data */ = {
|
||||
098FBDFA15D70E2F00623941 /* Stubs */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
097935A1161B654E006DB5D5 /* libOHHTTPStubs.a */,
|
||||
098FBDF615D70E2600623941 /* stub.jpg */,
|
||||
098FBDF715D70E2600623941 /* stub.txt */,
|
||||
);
|
||||
name = "Stub Data";
|
||||
name = Stubs;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
@ -189,8 +174,6 @@
|
|||
files = (
|
||||
098FBDE015D704E800623941 /* main.m in Sources */,
|
||||
098FBDED15D7056200623941 /* MainViewController.m in Sources */,
|
||||
098FBDF415D705E900623941 /* OHHTTPStubs.m in Sources */,
|
||||
098FBDF515D705E900623941 /* OHHTTPStubsResponse.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -248,9 +231,9 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = "OHHTTPStubsDemo/OHHTTPStubsDemo-Prefix.pch";
|
||||
INFOPLIST_FILE = "OHHTTPStubsDemo/OHHTTPStubsDemo-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
GCC_PREFIX_HEADER = "OHHTTPStubsDemo-Prefix.pch";
|
||||
INFOPLIST_FILE = "OHHTTPStubsDemo-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
|
@ -260,9 +243,9 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = "OHHTTPStubsDemo/OHHTTPStubsDemo-Prefix.pch";
|
||||
INFOPLIST_FILE = "OHHTTPStubsDemo/OHHTTPStubsDemo-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
GCC_PREFIX_HEADER = "OHHTTPStubsDemo-Prefix.pch";
|
||||
INFOPLIST_FILE = "OHHTTPStubsDemo-Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
|
@ -287,6 +270,7 @@
|
|||
098FBDE915D704E800623941 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
7
OHHTTPStubsDemo/OHHTTPStubsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
сгенерированный
Normal file
7
OHHTTPStubsDemo/OHHTTPStubsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
сгенерированный
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:OHHTTPStubsDemo.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
До Ширина: | Высота: | Размер: 46 KiB После Ширина: | Высота: | Размер: 46 KiB |
36
README.md
36
README.md
|
@ -10,9 +10,9 @@ A class to stub network requests easily: test your apps with fake network data (
|
|||
* [Using download speed instead of responseTime](#using-download-speed-instead-of-responsetime)
|
||||
* [Return quickly when `onlyCheck=YES`](#return-quickly-when-onlycheckyes)
|
||||
* [Stack multiple requestHandlers](#stack-multiple-requesthandlers)
|
||||
* [Complete Example](#complete-example)
|
||||
* [Complete Examples](#complete-examples)
|
||||
* [Using in your projects](#using-in-your-projects)
|
||||
* [Change Log](#change-log)
|
||||
* [ARC Support](#arc-support)
|
||||
* [License and Credits](#license-and-credits)
|
||||
|
||||
----
|
||||
|
@ -115,7 +115,7 @@ In this scenario, the response will not actually be used but will only be compar
|
|||
So in such cases (`onlyCheck==YES`), you can simply return `nil` if you don't want to provide a stubbed response,
|
||||
and **_any_ non-nil value** to indicate that you will provide a stubbed response later.
|
||||
|
||||
This may be useful if you intend to do some no-so-fast work to build your real `OHHTTPStubsResponse`
|
||||
This may be useful if you intend to do some not-so-fast work to build your real `OHHTTPStubsResponse`
|
||||
(like reading some large file for example): in that case you can quickly return a dummy value when `onlyCheck==YES`
|
||||
without the burden of building the actual `OHHTTPStubsResponse` object.
|
||||
You will obviously return the real `OHHTTPStubsResponse` in the later call when `onlyCheck==NO`.
|
||||
|
@ -139,7 +139,11 @@ You can remove the latest added handler with the `removeLastRequestHandler` meth
|
|||
|
||||
You can also remove any given handler with the `removeRequestHandler:` method. This method takes as a parameter the object returned by `addRequestHandler:`. _Note that this returned object is already retained by OHHTTPStubs, so you may keep it in a `__weak` variable._
|
||||
|
||||
## Complete example
|
||||
## Complete examples
|
||||
|
||||
Here is another example code below that uses the various techniques explained above.
|
||||
For a complete Xcode projet, see the `OHHTTPStubsDemo.xcworkspace` project in the repository.
|
||||
|
||||
|
||||
NSArray* stubs = [NSArray arrayWithObjects:@"file1", @"file2", nil];
|
||||
|
||||
|
@ -171,14 +175,32 @@ You can also remove any given handler with the `removeRequestHandler:` method. T
|
|||
[req start];
|
||||
|
||||
|
||||
## Using in your projects
|
||||
|
||||
The `OHHTTPStubs` project is provided as a Xcode project that generates a static library, to easily integrate it with your project.
|
||||
|
||||
So even if you can drag & drop the `.h` & `.m` files of `OHHTTPStubs` in your own project, a cleaner way to integrate it would be using an Xcode4 workspace:
|
||||
|
||||
* Add the `OHHTTPStubs.xcodeproj` project to your application workspace, next to your application project
|
||||
* Link `libOHHTTPStubs.a` with your application project:
|
||||
* Select your application project in the Project Navigator, then select your target in which you want to use `OHHTTPStubs`
|
||||
(for example your Tests target if you will only use `OHHTTPStubs`in your Unit Tests)
|
||||
* Go to the "Build Phase" tab and open the "Link Binary With Libraries" phase
|
||||
* Use the "+" button to add the `libOHHTTPStubs.a` library to the libraries linked with your project
|
||||
* When you need to use `OHHTTPStubs` classes, import the headers using square brackets: `#import <OHHTTPStubs/OHHTTPStubs.h>`
|
||||
|
||||
_Note: due to a bug in Xcode4, the `libOHHTTPStubs.a` file reference that will be added in your project once you added the
|
||||
library to the above build phase has sometimes its path **not** referenced "Relative to Build Products" as it should.
|
||||
In such case, select the `libOHHTTPStubs.a` file in your Project Navigator and change the "Location" dropdown menu
|
||||
in the Identity Inspector to "Relative to Build Products" and ensure that the relative path is only `libOHHTTPStubs.a`
|
||||
(without any garbage "../../../" subpath). In case you have this bug, you may also need to remove the strange
|
||||
"Library Search Path" (that contains the DerivedData subpath) that Xcode may just have added automatically too.
|
||||
Fixing this ensure that the project dependencies are detected correctly by Xcode. Hopefully this bug will be fixed in a future version of Xcode4._
|
||||
|
||||
## Change Log
|
||||
|
||||
The changelog is available [here in the dedicated wiki page](https://github.com/AliSoftware/OHHTTPStubs/wiki/ChangeLog).
|
||||
|
||||
## ARC Support
|
||||
|
||||
This classes now support both ARC and non-ARC projects :)
|
||||
|
||||
## License and Credits
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче