Skip to content

Commit

Permalink
switch to swift 5.9
Browse files Browse the repository at this point in the history
Signed-off-by: weak <[email protected]>
  • Loading branch information
weakfl committed Oct 17, 2023
1 parent 39ee3e1 commit 8794c3a
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7
5.9
4 changes: 2 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Model/NumberState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public struct NumberState: CustomStringConvertible, Equatable {

private func getActualValue() -> NSNumber {
if format?.contains("%d") == true {
return NSNumber(value: Int(value))
NSNumber(value: Int(value))
} else {
return NSNumber(value: value)
NSNumber(value: value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class OpenHABServerProperties: Decodable {

public func linkUrl(byType type: String?) -> String? {
if let index = links.firstIndex(where: { $0.type == type }) {
return links[index].url
links[index].url
} else {
return nil
nil
}
}
}
4 changes: 2 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {

public var mappingsOrItemOptions: [OpenHABWidgetMapping] {
if mappings.isEmpty, let itemOptions = item?.stateDescription?.options {
return itemOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) }
itemOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) }
} else {
return mappings
mappings
}
}

Expand Down
4 changes: 2 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Util/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ public extension Endpoint {

static func iconForDrawer(rootUrl: String, version: Int, icon: String) -> Endpoint {
if version == 2 {
return Endpoint(
Endpoint(
baseURL: rootUrl,
path: "/icon/\(icon).png",
queryItems: []
)
} else {
return Endpoint(
Endpoint(
baseURL: rootUrl,
path: "/images/\(icon).png",
queryItems: []
Expand Down
8 changes: 4 additions & 4 deletions OpenHABCore/Sources/OpenHABCore/Util/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public extension String {

internal var intValue: Int {
if let asNumber = NumberFormatter().number(from: self) {
return asNumber.intValue
asNumber.intValue
} else {
return Int.max
Int.max
}
}

Expand Down Expand Up @@ -140,9 +140,9 @@ extension String? {
var orEmpty: String {
switch self {
case let .some(value):
return value
value
case .none:
return ""
""
}
}
}
2 changes: 1 addition & 1 deletion openHAB/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
guard let self else { return }
os_log("Permission granted: %{PUBLIC}@", log: .notifications, type: .info, granted ? "YES" : "NO")
guard granted else { return }
self.getNotificationSettings()
getNotificationSettings()
}
}

Expand Down
10 changes: 5 additions & 5 deletions openHAB/OpenHABDrawerItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ enum OpenHABDrawerItem {
var localizedString: String {
switch self {
case .settings:
return NSLocalizedString("settings", comment: "")
NSLocalizedString("settings", comment: "")
case .notifications:
return NSLocalizedString("notifications", comment: "")
NSLocalizedString("notifications", comment: "")
}
}

static func openHABDrawerItem(localizedString: String) -> OpenHABDrawerItem {
switch localizedString {
case OpenHABDrawerItem.settings.localizedString:
return OpenHABDrawerItem.settings
OpenHABDrawerItem.settings
case OpenHABDrawerItem.notifications.localizedString:
return OpenHABDrawerItem.notifications
OpenHABDrawerItem.notifications
default:
return OpenHABDrawerItem.settings
OpenHABDrawerItem.settings
}
}
}
20 changes: 10 additions & 10 deletions openHAB/OpenHABDrawerTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,30 @@ class OpenHABDrawerTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return 1
1
case 1:
return uiTiles.count
uiTiles.count
case 2:
return sitemaps.count
sitemaps.count
case 3:
return drawerItems.count
drawerItems.count
default:
return 0
0
}
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Main"
"Main"
case 1:
return "Tiles"
"Tiles"
case 2:
return "Sitemaps"
"Sitemaps"
case 3:
return "System"
"System"
default:
return "Unknown"
"Unknown"
}
}

Expand Down
12 changes: 6 additions & 6 deletions openHAB/OpenHABSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return NSLocalizedString("openhab_connection", comment: "")
NSLocalizedString("openhab_connection", comment: "")
case 1:
return NSLocalizedString("application_settings", comment: "")
NSLocalizedString("application_settings", comment: "")
case 2:
return NSLocalizedString("mainui_settings", comment: "")
NSLocalizedString("mainui_settings", comment: "")
case 3:
return NSLocalizedString("sitemap_settings", comment: "")
NSLocalizedString("sitemap_settings", comment: "")
case 4:
return NSLocalizedString("about_settings", comment: "")
NSLocalizedString("about_settings", comment: "")
default:
return ""
""
}
}

Expand Down
28 changes: 14 additions & 14 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel

var relevantPage: OpenHABSitemapPage? {
if isFiltering {
return filteredPage
filteredPage
} else {
return currentPage
currentPage
}
}

Expand Down Expand Up @@ -337,7 +337,7 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel
var openHABSitemapPage: OpenHABSitemapPage?

// If we are talking to openHAB 1.X, talk XML
if self.appData?.openHABVersion == 1 {
if appData?.openHABVersion == 1 {
let str = String(decoding: data, as: UTF8.self)
os_log("%{PUBLIC}@", log: .remoteAccess, type: .info, str)

Expand All @@ -363,31 +363,31 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel
}
}

self.currentPage = openHABSitemapPage
if self.isFiltering {
self.filterContentForSearchText(self.search.searchBar.text)
currentPage = openHABSitemapPage
if isFiltering {
filterContentForSearchText(search.searchBar.text)
}

self.currentPage?.sendCommand = { [weak self] item, command in
currentPage?.sendCommand = { [weak self] item, command in
self?.sendCommand(item, commandToSend: command)
}
// isUserInteracting fixes https://github.com/openhab/openhab-ios/issues/646 where reloading while the user is interacting can have unintended consequences
if !self.isUserInteracting {
self.widgetTableView.reloadData()
self.refreshControl?.endRefreshing()
if !isUserInteracting {
widgetTableView.reloadData()
refreshControl?.endRefreshing()
} else {
self.isWaitingToReload = true
isWaitingToReload = true
}
self.parent?.navigationItem.title = self.currentPage?.title.components(separatedBy: "[")[0]
parent?.navigationItem.title = currentPage?.title.components(separatedBy: "[")[0]

self.loadPage(true)
loadPage(true)
case let .failure(error):
os_log("On LoadPage \"%{PUBLIC}@\" code: %d ", log: .remoteAccess, type: .error, error.localizedDescription, response.response?.statusCode ?? 0)

NetworkConnection.atmosphereTrackingId = ""
if (error as NSError?)?.code == -1001, longPolling {
os_log("Timeout, restarting requests", log: OSLog.remoteAccess, type: .error)
self.loadPage(false)
loadPage(false)
} else if error.isExplicitlyCancelledError {
os_log("Request was cancelled", log: OSLog.remoteAccess, type: .error)
} else {
Expand Down
8 changes: 4 additions & 4 deletions openHAB/OpenHABTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class OpenHABTracker: NSObject {
guard let self else { return }
let nStatus = status
// use a timer to prevent bouncing/flapping around when switching between wifi, vpn, and wwan
self.restartTimer?.invalidate()
self.restartTimer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { _ in
restartTimer?.invalidate()
restartTimer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { _ in
if nStatus != self.oldReachabilityStatus {
if let oldReachabilityStatus = self.oldReachabilityStatus {
os_log("OpenHABTracker Network status changed from %{PUBLIC}@ to %{PUBLIC}@", log: OSLog.remoteAccess, type: .info, self.string(from: oldReachabilityStatus) ?? "", self.string(from: nStatus) ?? "")
Expand Down Expand Up @@ -276,9 +276,9 @@ class OpenHABTracker: NSObject {
func string(from status: NetworkReachabilityManager.NetworkReachabilityStatus) -> String? {
switch status {
case .unknown, .notReachable:
return "unreachable"
"unreachable"
case let .reachable(connectionType):
return connectionType == .ethernetOrWiFi ? "WiFi" : "WWAN"
connectionType == .ethernetOrWiFi ? "WiFi" : "WWAN"
}
}

Expand Down
7 changes: 3 additions & 4 deletions openHAB/SetpointUITableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ class SetpointUITableViewCell: GenericUITableViewCell {
private func handleUpDown(down: Bool) {
var numberState = widget?.stateValueAsNumberState
let stateValue = numberState?.value ?? widget.minValue
let newValue: Double
switch down {
let newValue: Double = switch down {
case true:
newValue = stateValue - widget.step
stateValue - widget.step
case false:
newValue = stateValue + widget.step
stateValue + widget.step
}
if newValue >= widget.minValue, newValue <= widget.maxValue {
if numberState != nil {
Expand Down
4 changes: 2 additions & 2 deletions openHAB/SliderUITableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class SliderUITableViewCell: GenericUITableViewCell {

private func adjustedValue() -> Double {
if let item = widget.item {
return adj(item.stateAsDouble())
adj(item.stateAsDouble())
} else {
return widget.minValue
widget.minValue
}
}

Expand Down
12 changes: 5 additions & 7 deletions openHAB/SpinnerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import UIKit

class SpinnerViewController: UIViewController {
private var spinner: UIActivityIndicatorView = {
if #available(iOS 13.0, *) {
return UIActivityIndicatorView(style: .large)
} else {
return UIActivityIndicatorView(style: .gray)
}
}()
private var spinner: UIActivityIndicatorView = if #available(iOS 13.0, *) {
.init(style: .large)
} else {
.init(style: .gray)
}

override func loadView() {
view = UIView()
Expand Down
12 changes: 5 additions & 7 deletions openHAB/VideoUITableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ enum VideoEncoding: String {
}

class VideoUITableViewCell: GenericUITableViewCell {
private var activityIndicator: UIActivityIndicatorView = {
if #available(iOS 13.0, *) {
return UIActivityIndicatorView(style: .medium)
} else {
return UIActivityIndicatorView(style: .gray)
}
}()
private var activityIndicator: UIActivityIndicatorView = if #available(iOS 13.0, *) {
.init(style: .medium)
} else {
.init(style: .gray)
}

var didLoad: (() -> Void)?

Expand Down
14 changes: 7 additions & 7 deletions openHABIntents/IntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import OpenHABCore
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
switch intent {
case is OpenHABGetItemStateIntent: return GetItemStateIntentHandler()
case is OpenHABSetSwitchStateIntent: return SetSwitchStateIntentHandler()
case is OpenHABSetNumberValueIntent: return SetNumberValueIntentHandler()
case is OpenHABSetStringValueIntent: return SetStringValueIntentHandler()
case is OpenHABSetColorValueIntent: return SetColorValueIntentHandler()
case is OpenHABSetContactStateValueIntent: return SetContactStateValueIntentHandler()
default: return SetDimmerRollerValueIntentHandler()
case is OpenHABGetItemStateIntent: GetItemStateIntentHandler()
case is OpenHABSetSwitchStateIntent: SetSwitchStateIntentHandler()
case is OpenHABSetNumberValueIntent: SetNumberValueIntentHandler()
case is OpenHABSetStringValueIntent: SetStringValueIntentHandler()
case is OpenHABSetColorValueIntent: SetColorValueIntentHandler()
case is OpenHABSetContactStateValueIntent: SetContactStateValueIntentHandler()
default: SetDimmerRollerValueIntentHandler()
}
}
}
14 changes: 7 additions & 7 deletions openHABWatch Extension/OpenHABWatchTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class OpenHABWatchTracker: NSObject {
guard let self else { return }

let nStatus = path
if nStatus != self.oldReachabilityStatus {
if let oldReachabilityStatus = self.oldReachabilityStatus {
if nStatus != oldReachabilityStatus {
if let oldReachabilityStatus {
os_log("Network status changed from %{PUBLIC}@ to %{PUBLIC}@", log: OSLog.remoteAccess, type: .info, oldReachabilityStatus.debugDescription, nStatus.debugDescription)
}
self.oldReachabilityStatus = nStatus
(self.delegate as? OpenHABWatchTrackerExtendedDelegate)?.openHABTrackingNetworkChange(nStatus)
if self.isNetworkConnected() {
self.pathMonitor.cancel()
self.selectUrl()
oldReachabilityStatus = nStatus
(delegate as? OpenHABWatchTrackerExtendedDelegate)?.openHABTrackingNetworkChange(nStatus)
if isNetworkConnected() {
pathMonitor.cancel()
selectUrl()
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions openHABWatch Extension/Views/Rows/SetpointRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ struct SetpointRow: View {
private func handleUpDown(down: Bool) {
var numberState = widget.stateValueAsNumberState
let stateValue = numberState?.value ?? widget.minValue
let newValue: Double
switch down {
let newValue: Double = switch down {
case true:
newValue = stateValue - widget.step
stateValue - widget.step
case false:
newValue = stateValue + widget.step
stateValue + widget.step
}
if newValue >= widget.minValue, newValue <= widget.maxValue {
numberState?.value = newValue
Expand Down
Loading

0 comments on commit 8794c3a

Please sign in to comment.