Skip to content

Commit

Permalink
Support for Swift 4 (LoopKit#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 authored Jul 8, 2017
1 parent 202d845 commit 9355c33
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 21 deletions.
17 changes: 17 additions & 0 deletions Common/Extensions/WCSession+Swift4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// 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
}
2 changes: 1 addition & 1 deletion Loop.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

// Change this on first setup to your own unique organization identifier in
// reverse-domain name syntax.
MAIN_APP_BUNDLE_IDENTIFIER = com.loopkit
MAIN_APP_BUNDLE_IDENTIFIER = com.loudnate
10 changes: 6 additions & 4 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
435400351C9F878D00D5819C /* SetBolusUserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435400331C9F878D00D5819C /* SetBolusUserInfo.swift */; };
436A0DA51D236A2A00104B24 /* LoopError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 436A0DA41D236A2A00104B24 /* LoopError.swift */; };
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 */; };
Expand Down Expand Up @@ -402,6 +404,7 @@
43649A621C7A347F00523D7F /* CollectionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionType.swift; sourceTree = "<group>"; };
436A0DA41D236A2A00104B24 /* LoopError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoopError.swift; sourceTree = "<group>"; };
436FACED1D0BA636004E2427 /* InsulinDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsulinDataSource.swift; sourceTree = "<group>"; };
437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WCSession+Swift4.swift"; sourceTree = "<group>"; };
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 = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
43776F961B8022E90074EA36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1040,6 +1043,7 @@
43BFF0B31E45C1BE00FF19A9 /* NumberFormatter.swift */,
43BFF0B11E45C18400FF19A9 /* UIColor.swift */,
43BFF0C31E4659E700FF19A9 /* UIColor+HIG.swift */,
437272DE1F09E41200A3DA02 /* WCSession+Swift4.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1489,6 +1493,7 @@
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 */,
Expand Down Expand Up @@ -1548,6 +1553,7 @@
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 */,
Expand Down Expand Up @@ -2015,7 +2021,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -2034,7 +2039,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).statuswidget";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -2060,7 +2064,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -2087,7 +2090,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).LoopUI";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
4 changes: 2 additions & 2 deletions Loop/Extensions/CaseCountable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

protocol CaseCountable: RawRepresentable {}

extension CaseCountable where RawValue: Integer {
extension CaseCountable where RawValue == Int {
static var count: Int {
var i: RawValue = 0
while let new = Self(rawValue: i) { i = new.rawValue.advanced(by: 1) }
return Int(i.toIntMax())
return i
}
}
2 changes: 1 addition & 1 deletion Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ final class DeviceDataManager {
completion(.failure(LoopError.invalidData(details: errorStr)))
return
}
completion(.success(status: status, date: date))
completion(.success((status: status, date: date)))
case .failure(let error):
self.logger.addError("Failed to fetch pump status: \(error)", fromSource: "RileyLink")
completion(.failure(error))
Expand Down
1 change: 0 additions & 1 deletion Loop/Models/ServiceAuthentication/ShareService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ShareService: ServiceAuthentication {
value: customServer))
*/


if let username = username, let password = password, let url = url {
isAuthorized = true
client = ShareClient(username: username, password: password, shareServer: url.absoluteString)
Expand Down
22 changes: 13 additions & 9 deletions Loop/View Controllers/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu
tableView.register(RileyLinkDeviceTableViewCell.nib(), forCellReuseIdentifier: RileyLinkDeviceTableViewCell.className)

dataManagerObserver = NotificationCenter.default.addObserver(forName: nil, object: dataManager, queue: nil) { [weak self = self] (note) -> Void in
if let deviceManager = self?.dataManager.rileyLinkManager {
switch note.name {
case Notification.Name.DeviceManagerDidDiscoverDevice:
self?.tableView.insertRows(at: [IndexPath(row: deviceManager.devices.count - 1, section: Section.devices.rawValue)], with: .automatic)
case Notification.Name.DeviceConnectionStateDidChange:
if let device = note.userInfo?[RileyLinkDeviceManager.RileyLinkDeviceKey] as? RileyLinkDevice, let index = deviceManager.devices.index(where: { $0 === device }) {
self?.tableView.reloadRows(at: [IndexPath(row: index, section: Section.devices.rawValue)], with: .none)
DispatchQueue.main.async {
if let deviceManager = self?.dataManager.rileyLinkManager {
switch note.name {
case Notification.Name.DeviceManagerDidDiscoverDevice:
self?.tableView.insertRows(at: [IndexPath(row: deviceManager.devices.count - 1, section: Section.devices.rawValue)], with: .automatic)
case Notification.Name.DeviceConnectionStateDidChange,
Notification.Name.DeviceRSSIDidChange,
Notification.Name.DeviceNameDidChange:
if let device = note.userInfo?[RileyLinkDeviceManager.RileyLinkDeviceKey] as? RileyLinkDevice, let index = deviceManager.devices.index(where: { $0 === device }) {
self?.tableView.reloadRows(at: [IndexPath(row: index, section: Section.devices.rawValue)], with: .none)
}
default:
break
}
default:
break
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion LoopUI/Views/ChartPointsTouchHighlightLayerViewCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ final class ChartPointsTouchHighlightLayerViewCache {

private lazy var labelY: UILabel = {
let label = UILabel()
label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFontWeightBold)
#if swift(>=4)
label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFont.Weight.bold)
#else
label.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: UIFontWeightBold)
#endif

return label
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension AddCarbsInterfaceController: WKCrownDelegate {
accumulatedRotation += rotationalDelta

let remainder = accumulatedRotation.truncatingRemainder(dividingBy: rotationsPerCarb)
carbValue += Int((accumulatedRotation - remainder).divided(by: rotationsPerCarb))
carbValue += Int((accumulatedRotation - remainder) / rotationsPerCarb)
accumulatedRotation = remainder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension BolusInterfaceController: WKCrownDelegate {
accumulatedRotation += rotationalDelta

let remainder = accumulatedRotation.truncatingRemainder(dividingBy: rotationsPerValue)
pickerValue += Int((accumulatedRotation - remainder).divided(by: rotationsPerValue))
pickerValue += Int((accumulatedRotation - remainder) / rotationsPerValue)
accumulatedRotation = remainder
}
}

0 comments on commit 9355c33

Please sign in to comment.