From b2c4904a1b1ad080837445512336b95ffba213bb Mon Sep 17 00:00:00 2001 From: Manuel Meyer Date: Wed, 1 May 2019 18:43:13 +0200 Subject: [PATCH] Swift 5 for TEA --- .../Recordings.xcodeproj/project.pbxproj | 16 ++++++---- Recordings-TEA/Recordings/AppDelegate.swift | 2 +- Recordings-TEA/Recordings/Player.swift | 7 ++++- Recordings-TEA/Recordings/Recorder.swift | 7 ++++- .../Recordings/VirtualViews+Rendering.swift | 30 +++++++++---------- Recordings-TEA/Recordings/VirtualViews.swift | 25 ++++++++-------- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Recordings-TEA/Recordings.xcodeproj/project.pbxproj b/Recordings-TEA/Recordings.xcodeproj/project.pbxproj index 53ccb00..586da0b 100644 --- a/Recordings-TEA/Recordings.xcodeproj/project.pbxproj +++ b/Recordings-TEA/Recordings.xcodeproj/project.pbxproj @@ -249,17 +249,18 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0930; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = ""; TargetAttributes = { C90DE10C20830C580054A4BA = { CreatedOnToolsVersion = 9.3; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; TestTargetID = C9EB56BC1EAE33C1000EC5F4; }; C9EB56BC1EAE33C1000EC5F4 = { CreatedOnToolsVersion = 8.3.2; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; @@ -269,6 +270,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -377,7 +379,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.cocoawithlove.RecordingsTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Recordings.app/Recordings"; }; @@ -400,7 +402,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.cocoawithlove.RecordingsTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Recordings.app/Recordings"; }; @@ -410,6 +412,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -469,6 +472,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -528,7 +532,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.objc.Recordings-TEA"; PRODUCT_NAME = Recordings; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -543,7 +547,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.objc.Recordings-TEA"; PRODUCT_NAME = Recordings; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Recordings-TEA/Recordings/AppDelegate.swift b/Recordings-TEA/Recordings/AppDelegate.swift index 59f6f18..cdd9112 100644 --- a/Recordings-TEA/Recordings/AppDelegate.swift +++ b/Recordings-TEA/Recordings/AppDelegate.swift @@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { view: { state in state.viewController }, subscriptions: { state in state.subscriptions }) - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = driver.viewController window?.makeKeyAndVisible() diff --git a/Recordings-TEA/Recordings/Player.swift b/Recordings-TEA/Recordings/Player.swift index b72e9d9..e5aa04b 100644 --- a/Recordings-TEA/Recordings/Player.swift +++ b/Recordings-TEA/Recordings/Player.swift @@ -8,7 +8,7 @@ class Player: NSObject, AVAudioPlayerDelegate { init?(url: URL, update: ((TimeInterval?, _ isPlaying: Bool) -> ())? = nil) { do { - try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord) + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playAndRecord))) try AVAudioSession.sharedInstance().setActive(true) } catch { return nil @@ -71,3 +71,8 @@ class Player: NSObject, AVAudioPlayerDelegate { timer?.invalidate() } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String { + return input.rawValue +} diff --git a/Recordings-TEA/Recordings/Recorder.swift b/Recordings-TEA/Recordings/Recorder.swift index 7c48cf5..5fa0229 100644 --- a/Recordings-TEA/Recordings/Recorder.swift +++ b/Recordings-TEA/Recordings/Recorder.swift @@ -13,7 +13,7 @@ final class Recorder: NSObject, AVAudioRecorderDelegate { super.init() do { - try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord) + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playAndRecord))) try AVAudioSession.sharedInstance().setActive(true) AVAudioSession.sharedInstance().requestRecordPermission() { allowed in if allowed { @@ -58,3 +58,8 @@ final class Recorder: NSObject, AVAudioRecorderDelegate { } } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String { + return input.rawValue +} diff --git a/Recordings-TEA/Recordings/VirtualViews+Rendering.swift b/Recordings-TEA/Recordings/VirtualViews+Rendering.swift index b2a2bb3..bfbc33d 100644 --- a/Recordings-TEA/Recordings/VirtualViews+Rendering.swift +++ b/Recordings-TEA/Recordings/VirtualViews+Rendering.swift @@ -32,7 +32,7 @@ final class NCDelegate: NSObject, UINavigationControllerDelegate { self.popDetail = popDetail } - func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { if operation == .pop { if (navigationController.splitViewController?.delegate as? SplitViewControllerDelegate)?.detailViewController === fromVC { popDetail() @@ -67,7 +67,7 @@ class TableViewBacking: NSObject, UITableViewDataSource, UITableViewDelegate return cell } - func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete, let action = cells[indexPath.row].onDelete { callback?(action) } @@ -299,8 +299,8 @@ struct Renderer { } func childViewController(for existing: UIView) -> UIViewController? { - guard let i = container.childViewControllers.index(where: { $0.view == existing }) else { return nil } - return container.childViewControllers[i] + guard let i = container.children.firstIndex(where: { $0.view == existing }) else { return nil } + return container.children[i] } mutating func render(view: View) -> UIView { @@ -347,13 +347,13 @@ struct Renderer { } return v case let ._activityIndicator(indicator): - let result = UIActivityIndicatorView(activityIndicatorStyle: indicator.style) + let result = UIActivityIndicatorView(style: indicator.style) result.startAnimating() return result case ._childViewController(let vc): var result = UIViewController() strongReferences.append(vc.render(callback: callback, change: &result)) - container.addChildViewController(result) + container.addChild(result) addedChildViewControllers.append(result) return result.view case ._customLayout(let views): @@ -370,10 +370,10 @@ struct Renderer { } mutating func removeChildViewController(for view: UIView) { - guard let i = container.childViewControllers.index(where: { $0.view == view }) else { return } + guard let i = container.children.firstIndex(where: { $0.view == view }) else { return } - let child = container.childViewControllers[i] - child.willMove(toParentViewController: nil) + let child = container.children[i] + child.willMove(toParent: nil) removedChildViewControllers.append(child) } @@ -415,7 +415,7 @@ struct Renderer { removeChildViewController(for: existing) return render(view: view) } - a.activityIndicatorViewStyle = indicator.style + a.style = indicator.style return a case let ._textField(textField): guard let result = existing as? UITextField else { @@ -453,9 +453,9 @@ struct Renderer { var resultVC = existingVC strongReferences.append(vc.render(callback: callback, change: &resultVC)) if resultVC != existingVC { - existingVC.willMove(toParentViewController: nil) + existingVC.willMove(toParent: nil) removedChildViewControllers.append(existingVC) - container.addChildViewController(resultVC) + container.addChild(resultVC) addedChildViewControllers.append(resultVC) } return resultVC.view @@ -522,7 +522,7 @@ extension SplitViewController { let n = UINavigationController() n.navigationBar.barTintColor = .blueTint n.navigationBar.tintColor = .orangeTint - n.navigationBar.titleTextAttributes = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.white] + n.navigationBar.titleTextAttributes = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white] return n } @@ -624,10 +624,10 @@ extension ViewController { ]) } for removed in r.removedChildViewControllers { - removed.removeFromParentViewController() + removed.removeFromParent() } for added in r.addedChildViewControllers { - added.didMove(toParentViewController: change) + added.didMove(toParent: change) } return r.strongReferences case .splitViewController(let newSVC, let modal): diff --git a/Recordings-TEA/Recordings/VirtualViews.swift b/Recordings-TEA/Recordings/VirtualViews.swift index 37d182b..e849852 100644 --- a/Recordings-TEA/Recordings/VirtualViews.swift +++ b/Recordings-TEA/Recordings/VirtualViews.swift @@ -33,11 +33,11 @@ struct TextField { struct StackView { let views: [View] - let axis: UILayoutConstraintAxis - let distribution: UIStackViewDistribution + let axis: NSLayoutConstraint.Axis + let distribution: UIStackView.Distribution let backgroundColor: UIColor - init(views: [View], axis: UILayoutConstraintAxis = .vertical, distribution: UIStackViewDistribution = .equalCentering, backgroundColor: UIColor = .white) { + init(views: [View], axis: NSLayoutConstraint.Axis = .vertical, distribution: UIStackView.Distribution = .equalCentering, backgroundColor: UIColor = .white) { self.views = views self.axis = axis self.distribution = distribution @@ -65,16 +65,17 @@ struct TableViewCell: Hashable { static func ==(lhs: TableViewCell, rhs: TableViewCell) -> Bool { return lhs.identity == rhs.identity && lhs.text == rhs.text && lhs.accessory == rhs.accessory } - var hashValue: Int { - return identity.hashValue - } + func hash(into hasher: inout Hasher) { + hasher.combine(identity) + } + let identity: AnyHashable let text: String let onSelect: Message? let onDelete: Message? - let accessory: UITableViewCellAccessoryType - init(identity: AnyHashable, text: String, onSelect: Message?, accessory: UITableViewCellAccessoryType = .none, onDelete: Message?) { + let accessory: UITableViewCell.AccessoryType + init(identity: AnyHashable, text: String, onSelect: Message?, accessory: UITableViewCell.AccessoryType = .none, onDelete: Message?) { self.identity = identity self.text = text self.accessory = accessory @@ -105,7 +106,7 @@ struct Slider { enum BarButtonItem { case none case builtin(UIBarButtonItem) - case system(UIBarButtonSystemItem, action: Message) + case system(UIBarButtonItem.SystemItem, action: Message) case custom(text: String, action: Message) case editButtonItem @@ -140,7 +141,7 @@ struct Space { } struct ActivityIndicator { - let style: UIActivityIndicatorViewStyle + let style: UIActivityIndicatorView.Style } typealias Constraint = (_ child: UIView, _ parent: UIView) -> NSLayoutConstraint @@ -221,7 +222,7 @@ extension View { return ._imageView(ImageView(image: image)) } - static func stackView(views: [View], axis: UILayoutConstraintAxis = .vertical, distribution: UIStackViewDistribution = .equalCentering, backgroundColor: UIColor = .white) -> View { + static func stackView(views: [View], axis: NSLayoutConstraint.Axis = .vertical, distribution: UIStackView.Distribution = .equalCentering, backgroundColor: UIColor = .white) -> View { return ._stackView(StackView(views: views, axis: axis, distribution: distribution, backgroundColor: backgroundColor)) } @@ -237,7 +238,7 @@ extension View { return ._space(Space(width: width, height: height)) } - static func activityIndicator(style: UIActivityIndicatorViewStyle = .white) -> View { + static func activityIndicator(style: UIActivityIndicatorView.Style = .white) -> View { return ._activityIndicator(ActivityIndicator(style: style)) } }