Skip to content

Commit 86006a7

Browse files
authored
Merge pull request #1027 from LoopKit/swift5
Update to Swift 5
2 parents bbe1587 + 2157223 commit 86006a7

25 files changed

+156
-124
lines changed

Learn/Lessons/TimeInRangeLesson.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ private class TimeInRangeCalculator {
177177
os_log(.error, log: self.log, "Failed to fetch samples: %{public}@", String(describing: error))
178178
completion(error)
179179
case .success(let samples):
180-
181180
if let timeInRange = samples.proportion(where: { self.range.contains($0.quantity) }) {
182181
_ = results.mutate({ (results) in
183182
results[day] = timeInRange

Loop Status Extension/StatusViewController.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ class StatusViewController: UIViewController, NCWidgetProviding {
100100
extensionContext?.widgetLargestAvailableDisplayMode = .expanded
101101

102102
switch extensionContext?.widgetActiveDisplayMode ?? .compact {
103-
case .compact:
104-
glucoseChartContentView.isHidden = true
105103
case .expanded:
106104
glucoseChartContentView.isHidden = false
105+
case .compact:
106+
fallthrough
107+
@unknown default:
108+
glucoseChartContentView.isHidden = true
107109
}
108110

109111
observers = [
@@ -121,10 +123,12 @@ class StatusViewController: UIViewController, NCWidgetProviding {
121123
let compactHeight = hudView.systemLayoutSizeFitting(maxSize).height + subtitleLabel.systemLayoutSizeFitting(maxSize).height
122124

123125
switch activeDisplayMode {
124-
case .compact:
125-
preferredContentSize = CGSize(width: maxSize.width, height: compactHeight)
126126
case .expanded:
127127
preferredContentSize = CGSize(width: maxSize.width, height: compactHeight + 100)
128+
case .compact:
129+
fallthrough
130+
@unknown default:
131+
preferredContentSize = CGSize(width: maxSize.width, height: compactHeight)
128132
}
129133
}
130134

@@ -275,10 +279,12 @@ class StatusViewController: UIViewController, NCWidgetProviding {
275279
}
276280

277281
switch extensionContext?.widgetActiveDisplayMode ?? .compact {
278-
case .compact:
279-
glucoseChartContentView.isHidden = true
280282
case .expanded:
281283
glucoseChartContentView.isHidden = false
284+
case .compact:
285+
fallthrough
286+
@unknown default:
287+
glucoseChartContentView.isHidden = true
282288
}
283289

284290
// Right now we always act as if there's new data.

Loop.xcodeproj/project.pbxproj

Lines changed: 43 additions & 55 deletions
Large diffs are not rendered by default.

Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@
2020
ReferencedContainer = "container:Loop.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23-
<BuildActionEntry
24-
buildForTesting = "YES"
25-
buildForRunning = "YES"
26-
buildForProfiling = "YES"
27-
buildForArchiving = "YES"
28-
buildForAnalyzing = "YES">
29-
<BuildableReference
30-
BuildableIdentifier = "primary"
31-
BlueprintIdentifier = "C189E6AF22B410CA005904DA"
32-
BuildableName = "Merge Feature Flags"
33-
BlueprintName = "Merge Feature Flags"
34-
ReferencedContainer = "container:Loop.xcodeproj">
35-
</BuildableReference>
36-
</BuildActionEntry>
3723
<BuildActionEntry
3824
buildForTesting = "YES"
3925
buildForRunning = "YES"

Loop/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
2424
return window?.rootViewController as? RootNavigationController
2525
}
2626

27-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
27+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2828
window?.tintColor = UIColor.tintColor
2929

3030
NotificationManager.authorize(delegate: self)
@@ -56,7 +56,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
5656

5757
// MARK: - Continuity
5858

59-
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
59+
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
6060

6161
if #available(iOS 12.0, *) {
6262
if userActivity.activityType == NewCarbEntryIntent.className {

Loop/Extensions/RangeReplaceableCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extension RangeReplaceableCollection where Element: Equatable {
1010
/// Returns `true` if the element was removed, or `false` if it is not present in the collection.
1111
@discardableResult
1212
mutating func remove(_ element: Element) -> Bool {
13-
guard let index = self.index(of: element) else {
13+
guard let index = self.firstIndex(of: element) else {
1414
return false
1515
}
1616

Loop/Managers/LoopDataManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ final class LoopDataManager {
225225

226226
// MARK: - Background task management
227227

228-
private var backgroundTask: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
228+
private var backgroundTask: UIBackgroundTaskIdentifier = .invalid
229229

230230
private func startBackgroundTask() {
231231
endBackgroundTask()
@@ -235,9 +235,9 @@ final class LoopDataManager {
235235
}
236236

237237
private func endBackgroundTask() {
238-
if backgroundTask != UIBackgroundTaskInvalid {
238+
if backgroundTask != .invalid {
239239
UIApplication.shared.endBackgroundTask(backgroundTask)
240-
backgroundTask = UIBackgroundTaskInvalid
240+
backgroundTask = .invalid
241241
}
242242
}
243243
}

Loop/Managers/NotificationManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct NotificationManager {
7878
notification.body = error.localizedDescription
7979
}
8080

81-
notification.sound = UNNotificationSound.default()
81+
notification.sound = .default
8282

8383
if startDate.timeIntervalSinceNow >= TimeInterval(minutes: -5) {
8484
notification.categoryIdentifier = LoopNotificationCategory.bolusFailure.rawValue
@@ -122,7 +122,7 @@ struct NotificationManager {
122122
}
123123

124124
notification.title = NSLocalizedString("Loop Failure", comment: "The notification title for a loop failure")
125-
notification.sound = UNNotificationSound.default()
125+
notification.sound = .default
126126
notification.categoryIdentifier = LoopNotificationCategory.loopNotRunning.rawValue
127127
notification.threadIdentifier = LoopNotificationCategory.loopNotRunning.rawValue
128128

@@ -157,7 +157,7 @@ struct NotificationManager {
157157

158158
notification.title = NSLocalizedString("Pump Battery Low", comment: "The notification title for a low pump battery")
159159
notification.body = NSLocalizedString("Change the pump battery immediately", comment: "The notification alert describing a low pump battery")
160-
notification.sound = UNNotificationSound.default()
160+
notification.sound = .default
161161
notification.categoryIdentifier = LoopNotificationCategory.pumpBatteryLow.rawValue
162162

163163
let request = UNNotificationRequest(
@@ -178,7 +178,7 @@ struct NotificationManager {
178178

179179
notification.title = NSLocalizedString("Pump Reservoir Empty", comment: "The notification title for an empty pump reservoir")
180180
notification.body = NSLocalizedString("Change the pump reservoir now", comment: "The notification alert describing an empty pump reservoir")
181-
notification.sound = UNNotificationSound.default()
181+
notification.sound = .default
182182
notification.categoryIdentifier = LoopNotificationCategory.pumpReservoirEmpty.rawValue
183183

184184
let request = UNNotificationRequest(
@@ -211,7 +211,7 @@ struct NotificationManager {
211211
notification.body = String(format: NSLocalizedString("%1$@ U left", comment: "Low reservoir alert format string. (1: Number of units remaining)"), unitsString)
212212
}
213213

214-
notification.sound = UNNotificationSound.default()
214+
notification.sound = .default
215215
notification.categoryIdentifier = LoopNotificationCategory.pumpReservoirLow.rawValue
216216

217217
let request = UNNotificationRequest(

Loop/Managers/WatchDataManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ extension WatchDataManager: WCSessionDelegate {
279279
}
280280
case .inactive, .notActivated:
281281
break
282+
@unknown default:
283+
break
282284
}
283285
}
284286

Loop/View Controllers/CarbAbsorptionViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl
5656

5757
navigationItem.rightBarButtonItems?.append(editButtonItem)
5858

59-
tableView.rowHeight = UITableViewAutomaticDimension
59+
tableView.rowHeight = UITableView.automaticDimension
6060

6161
reloadData(animated: false)
6262
}
@@ -432,7 +432,7 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl
432432
}
433433
}
434434

435-
public override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
435+
public override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
436436
if editingStyle == .delete {
437437
let status = carbStatuses[indexPath.row]
438438
deviceManager.loopManager.carbStore.deleteCarbEntry(status.entry) { (result) -> Void in

0 commit comments

Comments
 (0)