Skip to content

Commit

Permalink
Merge pull request #50 from uphold/feature/migrate-swift3
Browse files Browse the repository at this point in the history
Xcode 8 & Swift 3 migration
  • Loading branch information
ruipenso authored Oct 2, 2017
2 parents 2b9c879 + 353f572 commit 8855188
Show file tree
Hide file tree
Showing 128 changed files with 1,767 additions and 1,170 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Carthage/
# Mac OS X
.DS_Store

# Swift package manager
.build/
Packages/

# Xcode settings
!default.mode1v3
!default.mode2v3
Expand Down
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
disabled_rules:
- conditional_binding_cascade
- control_statement
- file_length
- function_body_length
- function_parameter_count
- implicit_getter
- line_length
- type_body_length
- variable_name
- unused_optional_binding

included:
- SampleApplication
Expand Down
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
language: objective-c

osx_image: xcode7.3
osx_image: xcode8.3

env:
- SCHEME=UpholdSdk
- SCHEME=UpholdSdkSandbox

before_script:
- carthage update --platform iOS
# Workaround introduced to fix the xctool issue #454 (https://github.com/facebook/xctool/issues/454).
- open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID 75FC400A-B2AA-4DD6-B159-8687FAA5018A
- carthage bootstrap --platform iOS --no-build
- cd Carthage/Checkouts/URITemplate.swift && echo "IPHONEOS_DEPLOYMENT_TARGET = 8.0" > Configuration.xcconfig && swift package generate-xcodeproj --xcconfig-overrides Configuration.xcconfig
- cd ../../../
- carthage build --platform iOS --configuration ProductionRelease

script:
- swiftlint lint --strict
- xctool -project UpholdSdk.xcodeproj -scheme $SCHEME test sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- xcodebuild -project UpholdSdk.xcodeproj test -scheme $SCHEME -sdk iphonesimulator -destination "name=iPhone SE" | xcpretty
10 changes: 5 additions & 5 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github "Hearst-DD/ObjectMapper" ~> 1.2.0
github "mxcl/OMGHTTPURLRQ" ~> 3.1.2
github "mxcl/PromiseKit" ~> 3.2.1
github "marketplacer/keychain-swift" ~> 3.0.13
github "theadam/SwiftClient" ~> 2.0.3
github "Hearst-DD/ObjectMapper" ~> 2.2.8
github "mxcl/OMGHTTPURLRQ" ~> 3.2.2
github "mxcl/PromiseKit" ~> 4.1.8
github "marketplacer/keychain-swift" ~> 7.0.1
github "theadam/SwiftClient" ~> 3.0.3
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "vadymmarkov/Fakery" ~> 1.2.0
github "seegno-forks/Mockingjay" "support/add-carthage-configuration"
github "vadymmarkov/Fakery" ~> 2.0.0
github "uphold-forks/Mockingjay" "support/add-carthage-configuration"
14 changes: 7 additions & 7 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github "vadymmarkov/Fakery" "1.4.0"
github "vadymmarkov/Fakery" "2.0.0"
github "mxcl/OMGHTTPURLRQ" "3.2.2"
github "Hearst-DD/ObjectMapper" "1.5.0"
github "mxcl/PromiseKit" "3.5.3"
github "theadam/SwiftClient" "2.0.3"
github "kylef/URITemplate.swift" "175429f708de77e1c894e2fa4bc6c61f461822bb"
github "marketplacer/keychain-swift" "3.0.16"
github "seegno-forks/Mockingjay" "68b619819ecee654297ff2349b934032c33581f9"
github "Hearst-DD/ObjectMapper" "2.2.8"
github "mxcl/PromiseKit" "4.4.1"
github "theadam/SwiftClient" "3.0.3"
github "kylef/URITemplate.swift" "2.0.1"
github "marketplacer/keychain-swift" "7.0.1"
github "uphold-forks/Mockingjay" "40275c6b531fb9514327d9ce09e0acf9128a774c"
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The Uphold SDK for iOS provides an easy way for developers to integrate iOS appl

## Requirements

* Xcode 7
* Swift 2
* Xcode 8
* Swift 3
* Carthage or CocoaPods

## Installation
Expand All @@ -17,7 +17,7 @@ The Uphold SDK for iOS provides an easy way for developers to integrate iOS appl
1. Add to your `Podfile`.

```
platform :ios, '9.0'
platform :ios, '10.0'
use_frameworks!
# To use Uphold's production environment.
Expand Down Expand Up @@ -117,6 +117,8 @@ upholdClient.getUser().then { (user: User) -> () in
}
```

Note: Don't forget to add keychain sharing capabilities in your application's target inside the `Capabilities` tab.

### Get user cards with chaining

```swift
Expand Down Expand Up @@ -337,7 +339,8 @@ To build the sample application you need the [Xcode](https://developer.apple.com
```

3. Open the sample project `SampleApplication.xcodeproj`.
4. Build and run the app from inside Xcode.
4. Add keychain sharing capabilities.
5. Build and run the app from inside Xcode.

The sample application is configured to use the [sandbox environment](https://sandbox.uphold.com), make sure you use a sandbox account to perform the login.

Expand Down
39 changes: 34 additions & 5 deletions SampleApplication.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,18 @@
BC2381051BB461DE0060CC80 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Uphold;
TargetAttributes = {
BC23810C1BB461DE0060CC80 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = Q4SY8DMFN5;
LastSwiftMigration = 0800;
SystemCapabilities = {
com.apple.Keychain = {
enabled = 0;
};
};
};
};
};
Expand Down Expand Up @@ -329,8 +336,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 @@ -352,7 +361,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -365,11 +374,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = Q4SY8DMFN5;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = SampleApplication/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.uphold.sample;
PRODUCT_NAME = SampleApplication;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = ProductionDebug;
Expand All @@ -387,8 +399,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 @@ -404,9 +418,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -416,11 +431,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = Q4SY8DMFN5;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = SampleApplication/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.uphold.sample;
PRODUCT_NAME = SampleApplication;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = ProductionRelease;
Expand All @@ -438,8 +456,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 @@ -461,7 +481,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -483,8 +503,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 @@ -500,9 +522,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -512,11 +535,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = Q4SY8DMFN5;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = SampleApplication/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.uphold.sample;
PRODUCT_NAME = SampleApplication;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = SandboxDebug;
Expand All @@ -525,11 +551,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = Q4SY8DMFN5;
FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/Carthage/Build/iOS";
INFOPLIST_FILE = SampleApplication/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.uphold.sample;
PRODUCT_NAME = SampleApplication;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = SandboxRelease;
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
8 changes: 4 additions & 4 deletions SampleApplication/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

- returns: A boolean indicating if the application was launch successfully.
*/
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)

guard let window = self.window else {
return false
Expand All @@ -36,8 +36,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

- returns: A boolean indicating if the application can handle the URL resource or continue a user activity.
*/
func application(application: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
guard let window = self.window, rootViewController = window.rootViewController, loginViewController = rootViewController as? LoginViewController else {
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
guard let window = self.window, let rootViewController = window.rootViewController, let loginViewController = rootViewController as? LoginViewController else {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class LoginViewController: UIViewController, SFSafariViewControllerDelegate {

- parameter sender: The pressed login button.
*/
@IBAction func didTapLoginButton(sender: AnyObject) {
@IBAction func didTapLoginButton(_ sender: AnyObject) {
self.client = UpholdClient()
self.loginButton.enabled = false
self.loginButton.isEnabled = false
let scopes: [String] = ["cards:read", "user:read"]
self.state = String(format: "oauth2:%@", NSUUID().UUIDString)
self.state = String(format: "oauth2:%@", UUID().uuidString)

guard let client = self.client, state = self.state else {
guard let client = self.client, let state = self.state else {
self.handleError()

return
}

self.authorizationViewController = client.beginAuthorization(self, clientId: self.CLIENT_ID, scopes: scopes, state: state)
self.authorizationViewController = client.beginAuthorization(applicationViewController: self, clientId: self.CLIENT_ID, scopes: scopes, state: state)

guard let authorizationViewController = self.authorizationViewController else {
return
Expand All @@ -50,40 +50,40 @@ class LoginViewController: UIViewController, SFSafariViewControllerDelegate {

- parameter url: Authorization URL.
*/
func completeAuthorization(url: NSURL) {
func completeAuthorization(_ url: URL) {
let userViewController = UserViewController()

guard authorizationViewController = self.authorizationViewController, client = self.client, state = self.state else {
guard let authorizationViewController = self.authorizationViewController, let client = self.client, let state = self.state else {
return self.handleError()
}

client.completeAuthorization(authorizationViewController, clientId: self.CLIENT_ID, clientSecret: self.CLIENT_SECRET, grantType: "authorization_code", state: state, uri: url).then { (response: AuthenticationResponse) -> () in
client.completeAuthorization(authorizationViewController: authorizationViewController, clientId: self.CLIENT_ID, clientSecret: self.CLIENT_SECRET, grantType: "authorization_code", state: state, uri: url).then { (response: AuthenticationResponse) -> Void in
userViewController.bearerToken = response.accessToken

self.presentViewController(userViewController, animated: true, completion: nil)
}.error { (error: ErrorType) -> Void in
self.present(userViewController, animated: true, completion: nil)
}.catch(execute: { (_: Error) in
self.handleError()
}
})
}

/**
Handles login errors.
*/
func handleError() {
let alertController = UIAlertController(title: String(NSLocalizedString("login-view-controller.alert-title-login-error", comment: "Login Error.")), message: String(NSLocalizedString("global.unknown-error", comment: "Something went wrong.")), preferredStyle: .Alert)
self.loginButton.enabled = true
let alertController = UIAlertController(title: String(NSLocalizedString("login-view-controller.alert-title-login-error", comment: "Login Error.")), message: String(NSLocalizedString("global.unknown-error", comment: "Something went wrong.")), preferredStyle: .alert)
self.loginButton.isEnabled = true

alertController.addAction(UIAlertAction(title: String(NSLocalizedString("global.dismiss", comment: "Dismiss.")), style: .Default, handler: nil))
self.presentViewController(alertController, animated: true, completion:nil)
alertController.addAction(UIAlertAction(title: String(NSLocalizedString("global.dismiss", comment: "Dismiss.")), style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}

/**
Called when the user taps the done button to dismiss the Safari view.

- parameter controller: The view controller.
*/
func safariViewControllerDidFinish(controller: SFSafariViewController) {
self.loginButton.enabled = true
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
self.loginButton.isEnabled = true
}

}
Loading

0 comments on commit 8855188

Please sign in to comment.