Commit fb7816d9 authored by Drew's avatar Drew

Upgrade to Swift 3

parent 8a7b2a5c
......@@ -7,57 +7,32 @@ variables:
GITLAB_PROJECT_ID: "17"
FRAMEWORK_NAME: "SynchronousRequestKit"
xcs:
type: test
script:
- "/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI forceGitLabBranch --branchName CaveJohnsonAuto --hostname code.sealedabstract.com --projectID $GITLAB_PROJECT_ID"
- "sleep 1"
- "XCSBUILDNO=`/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI xcsIntegrateNow --botID $XCSBOT --hostname localhost --sslPolicy localhost`"
- "echo XCS BUILDNO $XCSBUILDNO"
- "/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI waitForIntegration --hostname localhost --botID $XCSBOT --sslPolicy localhost --buildNumber $XCSBUILDNO"
- "/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI xcsStatusToShell --hostname localhost --botID $XCSBOT --sslPolicy localhost --buildNumber $XCSBUILDNO"
only:
- master
tags:
- xc7
archive-mac:
type: package
script:
- "CJ=/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI"
- "CARTHAGE=/usr/local/bin/carthage"
- "$CJ setVersion --infoPlistPath $FRAMEWORK_NAME/Info.plist --version ${CI_BUILD_ID}"
- "$CARTHAGE build --no-skip-current --platform osx"
- "$CARTHAGE archive $FRAMEWORK_NAME"
- "ZIPFILE=$($CJ getNameVersionString --infoPlistPath $FRAMEWORK_NAME/Info.plist --productName $FRAMEWORK_NAME)-dev-${CI_BUILD_ID}.zip"
- "rm -rf /tmp/$FRAMEWORK_NAME/"
- "mkdir -p /tmp/$FRAMEWORK_NAME"
- "mv $FRAMEWORK_NAME.framework.zip /tmp/$FRAMEWORK_NAME/$ZIPFILE"
only:
- master
- "carthage build --no-skip-current --platform osx"
- "carthage archive $FRAMEWORK_NAME"
- mkdir bin
- mv SynchronousRequestKit.framework.zip bin/SynchronousRequestKit-OSX-${CI_BUILD_ID}.zip
artifacts:
paths:
- /tmp/SynchronousRequestKit/
- bin/
environment:
DEVELOPER_DIR=/Applications/Xcode8.app/Contents/Developer
archive-ios:
archive-mac:
type: package
script:
- "CJ=/Applications/CaveJohnson.app/Contents/MacOS/CaveJohnsonCLI"
- "CARTHAGE=/usr/local/bin/carthage"
- "$CJ setVersion --infoPlistPath $FRAMEWORK_NAME-iOS/Info.plist --version ${CI_BUILD_ID}"
- "$CARTHAGE build --no-skip-current --platform ios"
- "$CARTHAGE archive $FRAMEWORK_NAME"
- "ZIPFILE=$($CJ getNameVersionString --infoPlistPath $FRAMEWORK_NAME/Info.plist --productName $FRAMEWORK_NAME)-dev-${CI_BUILD_ID}.zip"
- "rm -rf /tmp/$FRAMEWORK_NAME/"
- "mkdir -p /tmp/$FRAMEWORK_NAME"
- "mv $FRAMEWORK_NAME.framework.zip /tmp/$FRAMEWORK_NAME/$ZIPFILE"
only:
- master
- "carthage build --no-skip-current --platform ios"
- "carthage archive $FRAMEWORK_NAME"
- mkdir bin
- mv SynchronousRequestKit.framework.zip bin/SynchronousRequestKit-iOS-${CI_BUILD_ID}.zip
artifacts:
paths:
- /tmp/SynchronousRequestKit/
- bin/
environment:
DEVELOPER_DIR=/Applications/Xcode8.app/Contents/Developer
......@@ -248,14 +248,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = DrewCrawfordApps;
TargetAttributes = {
3A0D8F7F1BB1299100A8ED0C = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
3A0D8F891BB1299100A8ED0C = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
3A9E705B1C21540E00C9430F = {
CreatedOnToolsVersion = 7.2;
......@@ -380,8 +382,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;
COPY_PHASE_STRIP = NO;
......@@ -408,6 +412,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
......@@ -426,8 +431,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;
COPY_PHASE_STRIP = NO;
......@@ -447,6 +454,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
......@@ -469,6 +477,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -488,6 +497,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.dca.SynchronousRequestKit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
......@@ -499,6 +509,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dca.SynchronousRequestKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -510,13 +521,14 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dca.SynchronousRequestKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
3A9E706E1C21540F00C9430F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
......@@ -536,7 +548,7 @@
3A9E706F1C21540F00C9430F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
......@@ -13,40 +13,40 @@ import Foundation
private var cassettes : [SynchronousDataTask] = []
/**Add a cassette to be played back on the next request. This is primarily used for testing purposes.*/
public func addCassette(string string: String) {
let response = NSHTTPURLResponse(URL: NSURL(), statusCode: 200, HTTPVersion: nil, headerFields: nil)
let cassette = SynchronousDataTask(task: NSURLSessionDataTask(), error: nil, data: string.dataUsingEncoding(NSUTF8StringEncoding), response:response)
public func addCassette(string: String) {
let response = HTTPURLResponse(url: URL(string: "http://www.example.com/")!, statusCode: 200, httpVersion: nil, headerFields: nil)
let cassette = SynchronousDataTask(task: URLSessionDataTask(), error: nil, data: string.data(using: String.Encoding.utf8), response:response)
cassettes.append(cassette)
}
public func addCassette(path path: String, testClass: AnyClass) {
let path = NSBundle(forClass: testClass).pathForResource(path, ofType: "cassette")
let data = NSData(contentsOfFile: path!)!
let str = NSString(data: data, encoding: NSUTF8StringEncoding)
public func addCassette(path: String, testClass: AnyClass) {
let path = Bundle(for: testClass).path(forResource: path, ofType: "cassette")
let data = try! Data(contentsOf: URL(fileURLWithPath: path!))
let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
addCassette(string: str as! String)
}
enum SynchronousDataTaskError : ErrorType {
case NoData
case BadHTTPStatus(code: Int, body: String?)
case NotHTTPResponse
case NoResponse
case NotUTF8
case NotJSONDict
enum SynchronousDataTaskError : Error {
case noData
case badHTTPStatus(code: Int, body: String?)
case notHTTPResponse
case noResponse
case notUTF8
case notJSONDict
}
import Foundation
private let errorDomain = "SynchronousDataTaskErrorDomain"
public final class SynchronousDataTask {
public var task: NSURLSessionDataTask
public var task: URLSessionDataTask
/**The error, if any, returned by Cocoa. If you want a better error, try errorOrData/errorOrString. */
public var underlyingCocoaError: NSError?
public var underlyingCocoaData: NSData?
public var underlyingCocoaResponse: NSURLResponse?
public var underlyingCocoaData: Data?
public var underlyingCocoaResponse: URLResponse?
private init(task: NSURLSessionDataTask, error: NSError?, data: NSData?, response:NSURLResponse?) {
fileprivate init(task: URLSessionDataTask, error: NSError?, data: Data?, response:URLResponse?) {
self.underlyingCocoaData = data
self.underlyingCocoaError = error
self.underlyingCocoaResponse = response
......@@ -58,22 +58,22 @@ public final class SynchronousDataTask {
This function tries to get some data for the request.
*/
public func getData() throws -> NSData {
public func getData() throws -> Data {
if let cocoaError = underlyingCocoaError { //may have an error already
throw cocoaError
}
if underlyingCocoaResponse == nil {
throw SynchronousDataTaskError.NoResponse
throw SynchronousDataTaskError.noResponse
}
guard let myResponse = underlyingCocoaResponse as? NSHTTPURLResponse else {
throw SynchronousDataTaskError.NotHTTPResponse
guard let myResponse = underlyingCocoaResponse as? HTTPURLResponse else {
throw SynchronousDataTaskError.notHTTPResponse
}
if myResponse.statusCode < 200 || myResponse.statusCode >= 300 {
throw SynchronousDataTaskError.BadHTTPStatus(code: myResponse.statusCode, body: _string)
throw SynchronousDataTaskError.badHTTPStatus(code: myResponse.statusCode, body: _string)
}
guard let d = underlyingCocoaData else {
throw SynchronousDataTaskError.NoData
throw SynchronousDataTaskError.noData
}
return d
}
......@@ -83,7 +83,7 @@ public final class SynchronousDataTask {
var _string : String? {
get {
guard let data = underlyingCocoaData else { return nil }
guard let str = NSString(data: data, encoding: NSUTF8StringEncoding) else { return nil }
guard let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return str as String
}
}
......@@ -94,57 +94,57 @@ public final class SynchronousDataTask {
*/
public func getString() throws -> String {
let data = try self.getData()
guard let str = NSString(data: data, encoding: NSUTF8StringEncoding) else { throw SynchronousDataTaskError.NotUTF8 }
guard let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { throw SynchronousDataTaskError.notUTF8 }
return str as String
}
/**This function tries to get a JSON dictionary for the request. */
public func getJsonDict() throws -> [String: AnyObject] {
let data = try getData()
let jsonObj = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions())
let jsonObj = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions())
if let j = jsonObj as? [String: AnyObject] {
return j
}
throw SynchronousDataTaskError.NotJSONDict
throw SynchronousDataTaskError.notJSONDict
}
/**This checks the response to see if it's a well-known string. */
public func isParticularError(code code: Int, body: String) -> Bool {
guard let myResponse = underlyingCocoaResponse as? NSHTTPURLResponse else { return false }
public func isParticularError(code: Int, body: String) -> Bool {
guard let myResponse = underlyingCocoaResponse as? HTTPURLResponse else { return false }
if myResponse.statusCode != code {
return false
}
guard let u = underlyingCocoaData else {
return false
}
let str = NSString(data: u, encoding: NSUTF8StringEncoding)
let str = NSString(data: u, encoding: String.Encoding.utf8.rawValue)
guard let s = str else { return false }
if s != body {
if s as String != body {
return false
}
return true
}
}
extension NSURLSession {
extension URLSession {
public func synchronousDataRequestWithRequest(request: NSURLRequest) -> SynchronousDataTask {
public func synchronousDataRequestWithRequest(_ request: URLRequest) -> SynchronousDataTask {
if cassettes.count > 0 {
return cassettes.removeFirst()
}
let sema = dispatch_semaphore_create(0)
var data : NSData?
var response : NSURLResponse?
let sema = DispatchSemaphore(value: 0)
var data : Data?
var response : URLResponse?
var error : NSError?
let task = self.dataTaskWithRequest(request) { (ldata, lresponse, lerror) -> Void in
let task = self.dataTask(with: request, completionHandler: { (ldata, lresponse, lerror) -> Void in
data = ldata
response = lresponse
error = lerror
dispatch_semaphore_signal(sema);
error = lerror as NSError?
sema.signal();
return;
}
})
task.resume()
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
sema.wait()
return SynchronousDataTask(task: task, error: error, data: data, response: response)
}
}
......@@ -28,7 +28,7 @@ class SynchronousRequestKitTests: XCTestCase {
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment