Skip to content

Commit

Permalink
Migrate to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Jun 29, 2016
1 parent 64abe39 commit a3b4bfe
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
16 changes: 16 additions & 0 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -557,27 +557,32 @@
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
};
14638CF91CC6459A002B9433 = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
};
14638D111CC646F9002B9433 = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
};
14638D271CC64747002B9433 = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
};
14638D3D1CC647E4002B9433 = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
};
146D72AB1AB782920058798C = {
Expand All @@ -589,6 +594,7 @@
44B5D3881D19B9E5004378B9 = {
DevelopmentTeam = C6K65RDJHL;
DevelopmentTeamName = "Elvis Nunez (Personal Team)";
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -878,6 +884,7 @@
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -898,6 +905,7 @@
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -920,6 +928,7 @@
PRODUCT_NAME = Networking;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -945,6 +954,7 @@
PRODUCT_NAME = Networking;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -971,6 +981,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -998,6 +1009,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -1024,6 +1036,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1050,6 +1063,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1080,6 +1094,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -1108,6 +1123,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
4 changes: 2 additions & 2 deletions Sources/Networking+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public extension Networking {
*/
public func imageFromCache(_ path: String, cacheName: String? = nil, completion: (image: NetworkingImage?) -> Void) {
self.objectFromCache(path, cacheName: cacheName, responseType: .image) { object in
TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(image: object as? NetworkingImage)
}
}
Expand All @@ -23,7 +23,7 @@ public extension Networking {
*/
public func downloadImage(_ path: String, cacheName: String? = nil, completion: (image: NetworkingImage?, error: NSError?) -> Void) {
self.request(.GET, path: path, cacheName: cacheName, parameterType: nil, parameters: nil, parts: nil, responseType: .image) { response, _, error in
TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(image: response as? NetworkingImage, error: error)
}
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Networking {
*/
case custom(String)

func contentType(boundary: String) -> String {
func contentType(_ boundary: String) -> String {
switch self {
case .json:
return "application/json"
Expand Down Expand Up @@ -152,7 +152,7 @@ public class Networking {
- parameter username: The username to be used.
- parameter password: The password to be used.
*/
public func authenticate(username: String, password: String) {
public func authenticate(_ username: String, password: String) {
let credentialsString = "\(username):\(password)"
if let credentialsData = credentialsString.data(using: String.Encoding.utf8) {
let base64Credentials = credentialsData.base64EncodedString([])
Expand All @@ -169,7 +169,7 @@ public class Networking {
Authenticates using a Bearer token, sets the Authorization header to "Bearer \(token)".
- parameter token: The token to be used.
*/
public func authenticate(token: String) {
public func authenticate(_ token: String) {
self.token = token
}

Expand All @@ -178,7 +178,7 @@ public class Networking {
- parameter authorizationHeaderKey: Sets this value as the key for the HTTP `Authorization` header
- parameter authorizationHeaderValue: Sets this value to the HTTP `Authorization` header or to the `headerKey` if you provided that.
*/
public func authenticate(headerKey: String = "Authorization", headerValue: String) {
public func authenticate(_ headerKey: String = "Authorization", headerValue: String) {
self.authorizationHeaderKey = headerKey
self.authorizationHeaderValue = headerValue
}
Expand Down Expand Up @@ -278,7 +278,7 @@ public class Networking {
sessionTask.cancel()
}

TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion?()
}
}
Expand All @@ -303,7 +303,7 @@ public class Networking {
*/
public func dataFromCache(_ path: String, cacheName: String? = nil, completion: (data: Data?) -> Void) {
self.objectFromCache(path, cacheName: cacheName, responseType: .data) { object in
TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(data: object as? Data)
}
}
Expand Down Expand Up @@ -421,15 +421,15 @@ extension Networking {
}
}

TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(response: returnedResponse, headers: headers, error: returnedError)
}
}
break
case .data, .image:
self.objectFromCache(path, cacheName: cacheName, responseType: responseType) { object in
if let object = object {
TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(response: object, headers: [String : AnyObject](), error: nil)
}
} else {
Expand All @@ -454,7 +454,7 @@ extension Networking {
break
}
}
TestCheck.testBlock(disabled: self.disableTestingMode) {
TestCheck.testBlock(self.disableTestingMode) {
completion(response: returnedResponse, headers: [String : AnyObject](), error: error)
}
}
Expand All @@ -474,7 +474,7 @@ extension Networking {
request.httpMethod = requestType.rawValue

if let parameterType = parameterType {
request.addValue(parameterType.contentType(boundary: self.boundary), forHTTPHeaderField: "Content-Type")
request.addValue(parameterType.contentType(self.boundary), forHTTPHeaderField: "Content-Type")
}

if let accept = responseType.accept {
Expand Down
6 changes: 3 additions & 3 deletions Sources/NetworkingImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension NetworkingImage {
}

#if os(OSX)
func data(type: NSBitmapImageFileType) -> Data? {
func data(_ type: NSBitmapImageFileType) -> Data? {
let imageData = self.tiffRepresentation!
let bitmapImageRep = NSBitmapImageRep(data: imageData)!
let data = bitmapImageRep.representation(using: type, properties: [String : AnyObject]())
Expand All @@ -32,15 +32,15 @@ extension NetworkingImage {

func pngData() -> Data? {
#if os(OSX)
return self.data(type: .PNG)
return self.data(.PNG)
#else
return UIImagePNGRepresentation(self)
#endif
}

func jpgData() -> Data? {
#if os(OSX)
return self.data(type: .JPEG)
return self.data(.JPEG)
#else
return UIImageJPEGRepresentation(self, 1)
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/TestCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct TestCheck {
/**
If it's in a unit testing target then it will return in the current thread, otherwise it will return in the main thread.
*/
static func testBlock(disabled: Bool, block: (Void) -> Void) {
static func testBlock(_ disabled: Bool, block: (Void) -> Void) {
if TestCheck.isTesting && disabled == false {
block()
} else {
Expand Down

0 comments on commit a3b4bfe

Please sign in to comment.