From 006a8cc91981f96308f9c54b751054ec2b228d57 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 7 Oct 2017 22:07:38 -0500 Subject: [PATCH] Remove Swift 3 support --- Common/Extensions/WCSession+Swift4.swift | 17 ------ Loop.xcodeproj/project.pbxproj | 6 --- Loop/Base.lproj/Main.storyboard | 54 +++++++------------ Loop/Managers/WatchDataManager.swift | 4 +- .../SettingsTableViewController.swift | 8 +-- Loop/Views/SwitchTableViewCell.swift | 11 +++- ...rtPointsTouchHighlightLayerViewCache.swift | 6 +-- .../AddCarbsInterfaceController.swift | 2 +- .../BolusInterfaceController.swift | 2 +- WatchApp Extension/ExtensionDelegate.swift | 12 ++--- 10 files changed, 44 insertions(+), 78 deletions(-) delete mode 100644 Common/Extensions/WCSession+Swift4.swift diff --git a/Common/Extensions/WCSession+Swift4.swift b/Common/Extensions/WCSession+Swift4.swift deleted file mode 100644 index 455dbeba5f..0000000000 --- a/Common/Extensions/WCSession+Swift4.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// WCSession.swift -// Loop -// -// Copyright © 2017 LoopKit Authors. All rights reserved. -// - -import WatchConnectivity - - -extension WCSession { - #if swift(>=4) - static func `default`() -> WCSession { - return self.default - } - #endif -} diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index a5c259baa0..9deb8153c7 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -64,8 +64,6 @@ 436A0DA51D236A2A00104B24 /* LoopError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 436A0DA41D236A2A00104B24 /* LoopError.swift */; }; 436D9BF81F6F4EA100CFA75F /* recommended_temp_start_low_end_just_above_range.json in Resources */ = {isa = PBXBuildFile; fileRef = 436D9BF71F6F4EA100CFA75F /* recommended_temp_start_low_end_just_above_range.json */; }; 436FACEE1D0BA636004E2427 /* InsulinDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 436FACED1D0BA636004E2427 /* InsulinDataSource.swift */; }; - 437272DF1F09E41200A3DA02 /* WCSession+Swift4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */; }; - 437272E01F09E41600A3DA02 /* WCSession+Swift4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */; }; 43776F901B8022E90074EA36 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43776F8F1B8022E90074EA36 /* AppDelegate.swift */; }; 43776F971B8022E90074EA36 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43776F951B8022E90074EA36 /* Main.storyboard */; }; 43776F991B8022E90074EA36 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 43776F981B8022E90074EA36 /* Assets.xcassets */; }; @@ -431,7 +429,6 @@ 436A0DA41D236A2A00104B24 /* LoopError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoopError.swift; sourceTree = ""; }; 436D9BF71F6F4EA100CFA75F /* recommended_temp_start_low_end_just_above_range.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = recommended_temp_start_low_end_just_above_range.json; sourceTree = ""; }; 436FACED1D0BA636004E2427 /* InsulinDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsulinDataSource.swift; sourceTree = ""; }; - 437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WCSession+Swift4.swift"; sourceTree = ""; }; 43776F8C1B8022E90074EA36 /* Loop.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Loop.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43776F8F1B8022E90074EA36 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 43776F961B8022E90074EA36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -1101,7 +1098,6 @@ 43BFF0B31E45C1BE00FF19A9 /* NumberFormatter.swift */, 43BFF0B11E45C18400FF19A9 /* UIColor.swift */, 43BFF0C31E4659E700FF19A9 /* UIColor+HIG.swift */, - 437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */, ); path = Extensions; sourceTree = ""; @@ -1573,7 +1569,6 @@ C178249A1E1999FA00D9D25C /* CaseCountable.swift in Sources */, 4F08DEA11E81D90F006741EA /* GlucoseRangeScheduleCalculator.swift in Sources */, 43DBF04C1C93B8D700B3C386 /* BolusViewController.swift in Sources */, - 437272DF1F09E41200A3DA02 /* WCSession+Swift4.swift in Sources */, 4FB76FBB1E8C42CF00B39636 /* UIColor.swift in Sources */, 4F6663941E905FD2009E74FC /* ChartColorPalette+Loop.swift in Sources */, 4328E0351CFC0AE100E199AA /* WatchDataManager.swift in Sources */, @@ -1640,7 +1635,6 @@ 43A943881B926B7B0051FA24 /* ExtensionDelegate.swift in Sources */, 4328E0291CFBE2C500E199AA /* NSUserDefaults.swift in Sources */, 4328E02F1CFBF81800E199AA /* WKInterfaceImage.swift in Sources */, - 437272E01F09E41600A3DA02 /* WCSession+Swift4.swift in Sources */, 4F2C15811E0495B200E160D4 /* WatchContext+WatchApp.swift in Sources */, 4328E02A1CFBE2C500E199AA /* UIColor.swift in Sources */, 4328E01B1CFBE1DA00E199AA /* BolusInterfaceController.swift in Sources */, diff --git a/Loop/Base.lproj/Main.storyboard b/Loop/Base.lproj/Main.storyboard index 0a16501bfb..41ad584e7d 100644 --- a/Loop/Base.lproj/Main.storyboard +++ b/Loop/Base.lproj/Main.storyboard @@ -20,37 +20,29 @@ - + - - - - - - - - - - - - - - @@ -70,7 +62,7 @@ - + @@ -218,35 +210,29 @@ - - - - - + + - - - @@ -1150,8 +1136,8 @@ - - - + + + diff --git a/Loop/Managers/WatchDataManager.swift b/Loop/Managers/WatchDataManager.swift index 82170ca6a0..101012339f 100644 --- a/Loop/Managers/WatchDataManager.swift +++ b/Loop/Managers/WatchDataManager.swift @@ -31,7 +31,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate { private var watchSession: WCSession? = { if WCSession.isSupported() { - return WCSession.default() + return WCSession.default } else { return nil } @@ -191,7 +191,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate { } func sessionDidDeactivate(_ session: WCSession) { - watchSession = WCSession.default() + watchSession = WCSession.default watchSession?.delegate = self watchSession?.activate() } diff --git a/Loop/View Controllers/SettingsTableViewController.swift b/Loop/View Controllers/SettingsTableViewController.swift index e18b5cbfda..4c530cff8b 100644 --- a/Loop/View Controllers/SettingsTableViewController.swift +++ b/Loop/View Controllers/SettingsTableViewController.swift @@ -202,7 +202,7 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu let switchCell = tableView.dequeueReusableCell(withIdentifier: SwitchTableViewCell.className, for: indexPath) as! SwitchTableViewCell switchCell.switch?.isOn = dataManager.loopManager.settings.dosingEnabled - switchCell.titleLabel.text = NSLocalizedString("Closed Loop", comment: "The title text for the looping enabled switch cell") + switchCell.textLabel?.text = NSLocalizedString("Closed Loop", comment: "The title text for the looping enabled switch cell") switchCell.switch?.addTarget(self, action: #selector(dosingEnabledChanged(_:)), for: .valueChanged) @@ -260,11 +260,11 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu switch row { case .enlite: switchCell.switch?.isOn = dataManager.cgm == .enlite - switchCell.titleLabel.text = NSLocalizedString("Sof-Sensor / Enlite", comment: "The title text for the Medtronic sensor switch cell") + switchCell.textLabel?.text = NSLocalizedString("Sof-Sensor / Enlite", comment: "The title text for the Medtronic sensor switch cell") switchCell.switch?.addTarget(self, action: #selector(enliteChanged(_:)), for: .valueChanged) case .g4: switchCell.switch?.isOn = dataManager.cgm == .g4 - switchCell.titleLabel.text = NSLocalizedString("G4 Share Receiver", comment: "The title text for the G4 Share Receiver switch cell") + switchCell.textLabel?.text = NSLocalizedString("G4 Share Receiver", comment: "The title text for the G4 Share Receiver switch cell") switchCell.switch?.addTarget(self, action: #selector(g4Changed(_:)), for: .valueChanged) case .g5: if case .g5? = dataManager.cgm { @@ -273,7 +273,7 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu switchCell.switch?.isOn = false } - switchCell.titleLabel.text = NSLocalizedString("G5 Transmitter", comment: "The title text for the G5 Transmitter switch cell") + switchCell.textLabel?.text = NSLocalizedString("G5 Transmitter", comment: "The title text for the G5 Transmitter switch cell") switchCell.switch?.addTarget(self, action: #selector(g5Changed(_:)), for: .valueChanged) case .dexcomShare, .g5TransmitterID: assertionFailure() diff --git a/Loop/Views/SwitchTableViewCell.swift b/Loop/Views/SwitchTableViewCell.swift index bfe5b04297..0cd4908a88 100644 --- a/Loop/Views/SwitchTableViewCell.swift +++ b/Loop/Views/SwitchTableViewCell.swift @@ -11,12 +11,19 @@ import UIKit final class SwitchTableViewCell: UITableViewCell { - @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var titleLabel: UILabel? @IBOutlet weak var subtitleLabel: UILabel? - @IBOutlet weak var `switch`: UISwitch? + var `switch`: UISwitch? + override func awakeFromNib() { + super.awakeFromNib() + + `switch` = UISwitch(frame: .zero) + accessoryView = `switch` + } + override func layoutSubviews() { super.layoutSubviews() diff --git a/LoopUI/Views/ChartPointsTouchHighlightLayerViewCache.swift b/LoopUI/Views/ChartPointsTouchHighlightLayerViewCache.swift index 7da757f9fb..eeb5b1fecb 100644 --- a/LoopUI/Views/ChartPointsTouchHighlightLayerViewCache.swift +++ b/LoopUI/Views/ChartPointsTouchHighlightLayerViewCache.swift @@ -19,11 +19,7 @@ final class ChartPointsTouchHighlightLayerViewCache { private lazy var labelY: UILabel = { let label = UILabel() - #if swift(>=4) - label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFont.Weight.bold) - #else - label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFontWeightBold) - #endif + label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFont.Weight.bold) return label }() diff --git a/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift b/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift index 18a0ccf1b0..5d14d3639b 100644 --- a/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift +++ b/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift @@ -101,7 +101,7 @@ final class AddCarbsInterfaceController: WKInterfaceController, IdentifiableClas let entry = CarbEntryUserInfo(value: Double(carbValue), absorptionTimeType: absorptionTime, startDate: Date()) do { - try WCSession.default().sendCarbEntryMessage(entry, + try WCSession.default.sendCarbEntryMessage(entry, replyHandler: { (suggestion) in WKExtension.shared().rootInterfaceController?.presentController(withName: BolusInterfaceController.className, context: suggestion) }, diff --git a/WatchApp Extension/Controllers/BolusInterfaceController.swift b/WatchApp Extension/Controllers/BolusInterfaceController.swift index 23c46fc12d..721100ace6 100644 --- a/WatchApp Extension/Controllers/BolusInterfaceController.swift +++ b/WatchApp Extension/Controllers/BolusInterfaceController.swift @@ -136,7 +136,7 @@ final class BolusInterfaceController: WKInterfaceController, IdentifiableClass { let bolus = SetBolusUserInfo(value: bolusValue, startDate: Date()) do { - try WCSession.default().sendBolusMessage(bolus) { (error) in + try WCSession.default.sendBolusMessage(bolus) { (error) in ExtensionDelegate.shared().present(error) } } catch { diff --git a/WatchApp Extension/ExtensionDelegate.swift b/WatchApp Extension/ExtensionDelegate.swift index a8cf4649c0..c77c95a126 100644 --- a/WatchApp Extension/ExtensionDelegate.swift +++ b/WatchApp Extension/ExtensionDelegate.swift @@ -21,7 +21,7 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { override init() { super.init() - let session = WCSession.default() + let session = WCSession.default session.delegate = self // It seems, according to [this sample code](https://developer.apple.com/library/prerelease/content/samplecode/QuickSwitch/Listings/QuickSwitch_WatchKit_Extension_ExtensionDelegate_swift.html#//apple_ref/doc/uid/TP40016647-QuickSwitch_WatchKit_Extension_ExtensionDelegate_swift-DontLinkElementID_8) @@ -47,8 +47,8 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { func applicationDidBecomeActive() { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - if WCSession.default().activationState != .activated { - WCSession.default().activate() + if WCSession.default.activationState != .activated { + WCSession.default.activate() } } @@ -92,8 +92,8 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { pendingConnectivityTasks.append(task) - if WCSession.default().activationState != .activated { - WCSession.default().activate() + if WCSession.default.activationState != .activated { + WCSession.default.activate() } completePendingConnectivityTasksIfNeeded() @@ -113,7 +113,7 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { private var pendingConnectivityTasks: [WKWatchConnectivityRefreshBackgroundTask] = [] private func completePendingConnectivityTasksIfNeeded() { - if WCSession.default().activationState == .activated && !WCSession.default().hasContentPending { + if WCSession.default.activationState == .activated && !WCSession.default.hasContentPending { pendingConnectivityTasks.forEach { (task) in if #available(watchOSApplicationExtension 4.0, *) { task.setTaskCompletedWithSnapshot(false)