Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to Swift 5 & iOS 13 #1354

Merged
merged 4 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Example/Standard Integration.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
TargetAttributes = {
04823F771A6849200098400B = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0920;
LastSwiftMigration = 1100;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplePay = {
Expand Down Expand Up @@ -501,7 +501,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -528,7 +528,7 @@
PRODUCT_NAME = "Standard Integration";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 3 additions & 3 deletions Example/Standard Integration/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Stripe
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let rootVC = BrowseProductsViewController()
let navigationController = UINavigationController(rootViewController: rootVC)
let window = UIWindow(frame: UIScreen.main.bounds)
Expand All @@ -24,7 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

// This method is where you handle URL opens if you are using a native scheme URLs (eg "yourexampleapp://")
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let stripeHandled = Stripe.handleURLCallback(with: url)

if (stripeHandled) {
Expand All @@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

// This method is where you handle URL opens if you are using univeral link URLs (eg "https://example.com/stripe_ios_callback")
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
if let url = userActivity.webpageURL {
let stripeHandled = Stripe.handleURLCallback(with: url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ class BrowseProductsViewController: UICollectionViewController {
self.navigationController?.navigationBar.barTintColor = theme.secondaryBackgroundColor
self.navigationController?.navigationBar.tintColor = theme.accentColor
let titleAttributes = [
NSAttributedStringKey.foregroundColor: theme.primaryForegroundColor,
NSAttributedStringKey.font: theme.font,
] as [NSAttributedStringKey : Any]
NSAttributedString.Key.foregroundColor: theme.primaryForegroundColor!,
NSAttributedString.Key.font: theme.font!,
] as [NSAttributedString.Key : Any]
let buttonAttributes = [
NSAttributedStringKey.foregroundColor: theme.accentColor,
NSAttributedStringKey.font: theme.font,
] as [NSAttributedStringKey : Any]
NSAttributedString.Key.foregroundColor: theme.accentColor!,
NSAttributedString.Key.font: theme.font!,
] as [NSAttributedString.Key : Any]
self.navigationController?.navigationBar.titleTextAttributes = titleAttributes
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(buttonAttributes, for: UIControlState())
self.navigationItem.backBarButtonItem?.setTitleTextAttributes(buttonAttributes, for: UIControlState())
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(buttonAttributes, for: UIControl.State())
self.navigationItem.backBarButtonItem?.setTitleTextAttributes(buttonAttributes, for: UIControl.State())
}

@objc func showSettings() {
let navController = UINavigationController(rootViewController: settingsVC)
navController.modalPresentationStyle = .fullScreen
self.present(navController, animated: true, completion: nil)
}

Expand Down
4 changes: 2 additions & 2 deletions Example/Standard Integration/Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BuyButton: UIButton {
override var isEnabled: Bool {
didSet {
let color = isEnabled ? enabledColor : disabledColor
setTitleColor(.white, for: UIControlState())
setTitleColor(.white, for: UIControl.State())
backgroundColor = color
}
}
Expand All @@ -51,7 +51,7 @@ class BuyButton: UIButton {
layer.shadowRadius = 7
layer.shadowOffset = CGSize(width: 0, height: 7)

setTitle(title, for: UIControlState())
setTitle(title, for: UIControl.State())
titleLabel!.font = type(of: self).defaultFont
isEnabled = enabled
}
Expand Down
6 changes: 3 additions & 3 deletions Example/Standard Integration/CheckoutRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CheckoutRowView: UIView {

fileprivate let titleLabel = UILabel()
fileprivate let detailLabel = UILabel()
fileprivate let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
fileprivate let activityIndicator = UIActivityIndicatorView(style: .gray)
fileprivate let backgroundView = HighlightingButton()

convenience init(title: String, detail: String, tappable: Bool = true) {
Expand All @@ -66,12 +66,12 @@ class CheckoutRowView: UIView {
self.backgroundColor = .white

self.detailLabel.textColor = .gray
self.activityIndicator.activityIndicatorViewStyle = .gray
self.activityIndicator.style = .gray
#if canImport(CryptoKit)
if #available(iOS 13.0, *) {
self.backgroundColor = .systemBackground
self.detailLabel.textColor = .secondaryLabel
self.activityIndicator.activityIndicatorViewStyle = .medium
self.activityIndicator.style = .medium
}
#endif

Expand Down
10 changes: 7 additions & 3 deletions Example/Standard Integration/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate {
let totalRow: CheckoutRowView
let buyButton: BuyButton
let rowHeight: CGFloat = 52
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
let activityIndicator = UIActivityIndicatorView(style: .gray)
let numberFormatter: NumberFormatter
var products: [Product]
var paymentInProgress: Bool = false {
Expand Down Expand Up @@ -170,7 +170,7 @@ See https://stripe.com/docs/testing.
var red: CGFloat = 0

self.theme.primaryBackgroundColor.getRed(&red, green: nil, blue: nil, alpha: nil)
self.activityIndicator.activityIndicatorViewStyle = red < 0.5 ? .white : .gray
self.activityIndicator.style = red < 0.5 ? .white : .gray
self.navigationItem.title = "Checkout"

// Footer
Expand All @@ -193,7 +193,7 @@ See https://stripe.com/docs/testing.
spacerView.heightAnchor.constraint(equalToConstant: BuyButton.defaultHeight + 8).isActive = true
let footerContainerView = UIStackView(arrangedSubviews: [shippingRow, makeSeparatorView(), paymentRow, makeSeparatorView(), totalRow, spacerView].compactMap({ $0 }))
footerContainerView.axis = .vertical
footerContainerView.frame = CGRect(x: 0, y: 0, width: 0, height: footerContainerView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height)
footerContainerView.frame = CGRect(x: 0, y: 0, width: 0, height: footerContainerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height)

self.activityIndicator.alpha = 0
self.buyButton.addTarget(self, action: #selector(didTapBuy), for: .touchUpInside)
Expand Down Expand Up @@ -298,6 +298,8 @@ See https://stripe.com/docs/testing.
completion(.error, actionError)
case .canceled:
completion(.userCancellation, nil)
@unknown default:
completion(.error, nil)
}
}
}
Expand All @@ -316,6 +318,8 @@ See https://stripe.com/docs/testing.
message = "Your purchase was successful!"
case .userCancellation:
return
@unknown default:
return
}
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
Expand Down
2 changes: 1 addition & 1 deletion Example/Standard Integration/EmojiCheckoutCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EmojiCheckoutCell: UITableViewCell {
let detailLabel: UILabel
let priceLabel: UILabel

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
priceLabel = UILabel()
priceLabel.font = UIFont.systemFont(ofSize: 18, weight: .regular)
detailLabel = UILabel()
Expand Down
6 changes: 3 additions & 3 deletions Example/Standard Integration/MyAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??),
let secret = json?["secret"] as? String else {
completion(nil, error)
return
Expand All @@ -71,7 +71,7 @@ class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??),
let secret = json?["secret"] as? String else {
completion(nil, error)
return
Expand All @@ -91,7 +91,7 @@ class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any] else {
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??) else {
completion(nil, error)
return
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Standard Integration/PaymentContextFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Stripe

class PaymentContextFooterView: UIView {

var insetMargins: UIEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)
var insetMargins: UIEdgeInsets = UIEdgeInsets.init(top: 10, left: 10, bottom: 10, right: 10)

var text: String = "" {
didSet {
Expand Down Expand Up @@ -40,7 +40,7 @@ class PaymentContextFooterView: UIView {
}

override func layoutSubviews() {
textLabel.frame = UIEdgeInsetsInsetRect(self.bounds, insetMargins)
textLabel.frame = self.bounds.inset(by: insetMargins)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
Expand Down
6 changes: 3 additions & 3 deletions Example/UI Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
TargetAttributes = {
C1140CBC1F1EC0FC002084AB = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0920;
LastSwiftMigration = 1100;
};
};
};
Expand Down Expand Up @@ -346,7 +346,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.stripe.uiexamples;
PRODUCT_NAME = "Stripe UI Examples";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -360,7 +360,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.stripe.uiexamples;
PRODUCT_NAME = "Stripe UI Examples";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion Example/UI Examples/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let rootVC = BrowseViewController()
let navController = UINavigationController(rootViewController: rootVC)
let window = UIWindow(frame: UIScreen.main.bounds)
Expand Down
2 changes: 1 addition & 1 deletion Example/UI Examples/MockCustomerContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MockCustomerContext: STPCustomerContext {
}

override func detachPaymentMethod(fromCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? = nil) {
if let index = customer.paymentMethods.index(where: { $0.stripeId == paymentMethod.stripeId }) {
if let index = customer.paymentMethods.firstIndex(where: { $0.stripeId == paymentMethod.stripeId }) {
customer.paymentMethods.remove(at: index)
}
if let completion = completion {
Expand Down