Skip to content

Commit

Permalink
Merge pull request #240 from AliSoftware/Xcode-8.3
Browse files Browse the repository at this point in the history
Xcode 8.3 and Swift 3.x support
  • Loading branch information
AliSoftware authored Mar 30, 2017
2 parents 8ecb062 + 4c418b3 commit 8660a5a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 81 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ matrix:
env: RAKETASK="osx[Mac Framework,x86_64,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
- osx_image: xcode7.3
env: RAKETASK="tvos[tvOS Framework,latest,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
- osx_image: xcode8
- osx_image: xcode8.3
env: RAKETASK="ios[iOS StaticLib,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
- osx_image: xcode8
- osx_image: xcode8.3
env: RAKETASK="ios[iOS Framework,latest,build-for-testing test-without-building]"
- osx_image: xcode8
- osx_image: xcode8.3
env: RAKETASK="osx[Mac Framework,x86_64,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
- osx_image: xcode8
- osx_image: xcode8.3
env: RAKETASK="tvos[tvOS Framework,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"

script:
Expand Down
2 changes: 1 addition & 1 deletion Examples/Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
62 changes: 31 additions & 31 deletions Examples/Swift/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class MainViewController: UIViewController {

installTextStub(self.installTextStubSwitch)
installImageStub(self.installImageStubSwitch)
OHHTTPStubs.onStubActivation { (request: NSURLRequest, stub: OHHTTPStubsDescriptor, response: OHHTTPStubsResponse) in
print("[OHHTTPStubs] Request to \(request.URL!) has been stubbed with \(stub.name)")
OHHTTPStubs.onStubActivation { (request: URLRequest, stub: OHHTTPStubsDescriptor, response: OHHTTPStubsResponse) in
print("[OHHTTPStubs] Request to \(request.url!) has been stubbed with \(String(describing: stub.name))")
}
}

////////////////////////////////////////////////////////////////////////////////
// MARK: - Global stubs activation

@IBAction func toggleStubs(sender: UISwitch) {
OHHTTPStubs.setEnabled(sender.on)
self.delaySwitch.enabled = sender.on
self.installTextStubSwitch.enabled = sender.on
self.installImageStubSwitch.enabled = sender.on
@IBAction func toggleStubs(_ sender: UISwitch) {
OHHTTPStubs.setEnabled(sender.isOn)
self.delaySwitch.isEnabled = sender.isOn
self.installTextStubSwitch.isEnabled = sender.isOn
self.installImageStubSwitch.isEnabled = sender.isOn

let state = sender.on ? "and enabled" : "but disabled"
let state = sender.isOn ? "and enabled" : "but disabled"
print("Installed (\(state)) stubs: \(OHHTTPStubs.allStubs)")
}

Expand All @@ -52,30 +52,30 @@ class MainViewController: UIViewController {
// MARK: - Text Download and Stub


@IBAction func downloadText(sender: UIButton) {
sender.enabled = false
@IBAction func downloadText(_ sender: UIButton) {
sender.isEnabled = false
self.textView.text = nil

let urlString = "http://www.opensource.apple.com/source/Git/Git-26/src/git-htmldocs/git-commit.txt?txt"
let req = NSURLRequest(URL: NSURL(string: urlString)!)
let req = URLRequest(url: URL(string: urlString)!)

NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue.mainQueue()) { (_, data, _) in
sender.enabled = true
if let receivedData = data, receivedText = NSString(data: receivedData, encoding: NSASCIIStringEncoding) {
NSURLConnection.sendAsynchronousRequest(req, queue: OperationQueue.main) { (_, data, _) in
sender.isEnabled = true
if let receivedData = data, let receivedText = NSString(data: receivedData, encoding: String.Encoding.ascii.rawValue) {
self.textView.text = receivedText as String
}
}
}

weak var textStub: OHHTTPStubsDescriptor?
@IBAction func installTextStub(sender: UISwitch) {
if sender.on {
@IBAction func installTextStub(_ sender: UISwitch) {
if sender.isOn {
// Install

textStub = stub(isExtension("txt")) { _ in
let stubPath = OHPathForFile("stub.txt", self.dynamicType)
return fixture(stubPath!, headers: ["Content-Type":"text/plain"])
.requestTime(self.delaySwitch.on ? 2.0 : 0.0, responseTime:OHHTTPStubsDownloadSpeedWifi)
textStub = stub(condition: isExtension("txt")) { _ in
let stubPath = OHPathForFile("stub.txt", type(of: self))
return fixture(filePath: stubPath!, headers: ["Content-Type":"text/plain"])
.requestTime(self.delaySwitch.isOn ? 2.0 : 0.0, responseTime:OHHTTPStubsDownloadSpeedWifi)
}
textStub?.name = "Text stub"
} else {
Expand All @@ -88,30 +88,30 @@ class MainViewController: UIViewController {
////////////////////////////////////////////////////////////////////////////////
// MARK: - Image Download and Stub

@IBAction func downloadImage(sender: UIButton) {
sender.enabled = false
@IBAction func downloadImage(_ sender: UIButton) {
sender.isEnabled = false
self.imageView.image = nil

let urlString = "http://images.apple.com/support/assets/images/products/iphone/hero_iphone4-5_wide.png"
let req = NSURLRequest(URL: NSURL(string: urlString)!)
let req = URLRequest(url: URL(string: urlString)!)

NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue.mainQueue()) { (_, data, _) in
sender.enabled = true
NSURLConnection.sendAsynchronousRequest(req, queue: OperationQueue.main) { (_, data, _) in
sender.isEnabled = true
if let receivedData = data {
self.imageView.image = UIImage(data: receivedData)
}
}
}

weak var imageStub: OHHTTPStubsDescriptor?
@IBAction func installImageStub(sender: UISwitch) {
if sender.on {
@IBAction func installImageStub(_ sender: UISwitch) {
if sender.isOn {
// Install

imageStub = stub(isExtension("png") || isExtension("jpg") || isExtension("gif")) { _ in
let stubPath = OHPathForFile("stub.jpg", self.dynamicType)
return fixture(stubPath!, headers: ["Content-Type":"image/jpeg"])
.requestTime(self.delaySwitch.on ? 2.0 : 0.0, responseTime: OHHTTPStubsDownloadSpeedWifi)
imageStub = stub(condition: isExtension("png") || isExtension("jpg") || isExtension("gif")) { _ in
let stubPath = OHPathForFile("stub.jpg", type(of: self))
return fixture(filePath: stubPath!, headers: ["Content-Type":"image/jpeg"])
.requestTime(self.delaySwitch.isOn ? 2.0 : 0.0, responseTime: OHHTTPStubsDownloadSpeedWifi)
}
imageStub?.name = "Image stub"
} else {
Expand Down
14 changes: 11 additions & 3 deletions Examples/Swift/OHHTTPStubsDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = AliSoftware;
TargetAttributes = {
099F74061AE2D049001108A5 = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
ProvisioningStyle = Manual;
};
};
Expand Down Expand Up @@ -261,8 +262,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -290,7 +293,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -308,8 +311,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -328,7 +333,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -338,6 +344,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FE789C901264C7AF3BDF48CB /* Pods-OHHTTPStubsDemo.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand All @@ -351,6 +358,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 0BFB1DB3496791F522727353 /* Pods-OHHTTPStubsDemo.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
74 changes: 37 additions & 37 deletions Examples/Swift/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@
MODULEMAP_FILE = "$(SRCROOT)/Supporting Files/module.modulemap";
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
Expand Down Expand Up @@ -1359,7 +1359,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
MODULEMAP_FILE = "$(SRCROOT)/Supporting Files/module.modulemap";
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
};
Expand Down
6 changes: 6 additions & 0 deletions OHHTTPStubs/Sources/Swift/OHHTTPStubsSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@
* - Returns: The `OHHTTPStubsResponse` instance that will stub with the given status code
* & headers, and use the file content as the response body.
*/
#if swift(>=3.0)
public func fixture(filePath: String, status: Int32 = 200, headers: [AnyHashable: Any]?) -> OHHTTPStubsResponse {
return OHHTTPStubsResponse(fileAtPath: filePath, statusCode: status, headers: headers)
}
#else
public func fixture(filePath: String, status: Int32 = 200, headers: [NSObject: AnyObject]?) -> OHHTTPStubsResponse {
return OHHTTPStubsResponse(fileAtPath: filePath, statusCode: status, headers: headers)
}
#endif

/**
* Helper to call the stubbing function in a more concise way?
Expand Down
4 changes: 2 additions & 2 deletions OHHTTPStubs/UnitTests/Test Suites/SwiftHelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SwiftHelpersTests : XCTestCase {
let req = NSURLRequest(URL: NSURL(string: url)!)
#endif
let p = req.url?.path
print("URL: \(url) -> Path: \(p)")
print("URL: \(url) -> Path: \(String(reflecting: p))")
XCTAssert(matcher(req) == result, "isPath(\"\(path)\" matcher failed when testing url \(url)")
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ class SwiftHelpersTests : XCTestCase {
let req = NSURLRequest(URL: NSURL(string: url)!)
#endif
let p = req.url?.path
print("URL: \(url) -> Path: \(p)")
print("URL: \(url) -> Path: \(String(reflecting: p))")
XCTAssert(matcher(req) == result, "pathStartsWith(\"\(path)\" matcher failed when testing url \(url)")
}
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ OHHTTPStubs
[![Version](http://cocoapod-badges.herokuapp.com/v/OHHTTPStubs/badge.png)](http://cocoadocs.org/docsets/OHHTTPStubs)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Build Status](https://travis-ci.org/AliSoftware/OHHTTPStubs.svg?branch=master)](https://travis-ci.org/AliSoftware/OHHTTPStubs)
[![Language: Swift 3.1](https://img.shields.io/badge/Swift-3.1-orange.svg)](https://swift.org)

`OHHTTPStubs` is a library designed to stub your network requests very easily. It can help you:

Expand Down

0 comments on commit 8660a5a

Please sign in to comment.