Skip to content

Commit

Permalink
Integrated SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
rwbutler committed May 13, 2022
1 parent 96a6057 commit f7f70e7
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 40 deletions.
7 changes: 0 additions & 7 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

This file was deleted.

21 changes: 11 additions & 10 deletions Connectivity/Classes/Connectivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Connectivity: NSObject {
public var framework: Connectivity.Framework = .systemConfiguration

/// Used to for checks using NWPathMonitor
private var internalQueue: DispatchQueue = DispatchQueue.global(qos: .background)
private var internalQueue = DispatchQueue.global(qos: .background)

/// Whether or not we are currently deemed to have connectivity
public private(set) var isConnected: Bool = false
Expand All @@ -92,9 +92,10 @@ public class Connectivity: NSObject {
didSet {
// Only set true if `allow arbitrary loads` is set
guard let bundleInfo = Bundle.main.infoDictionary,
let appTransportSecurity = bundleInfo["NSAppTransportSecurity"] as? [String: Any],
let allowsArbitraryLoads = appTransportSecurity["NSAllowsArbitraryLoads"] as? Bool,
allowsArbitraryLoads else {
let appTransportSecurity = bundleInfo["NSAppTransportSecurity"] as? [String: Any],
let allowsArbitraryLoads = appTransportSecurity["NSAllowsArbitraryLoads"] as? Bool,
allowsArbitraryLoads
else {
isHTTPSOnly = true
return
}
Expand Down Expand Up @@ -126,7 +127,7 @@ public class Connectivity: NSObject {
private var previousStatus: ConnectivityStatus = .determining

/// Queue to callback on
private var externalQueue: DispatchQueue = DispatchQueue.main
private var externalQueue = DispatchQueue.main

/// Reachability instance for checking network adapter status
private let reachability: Reachability
Expand Down Expand Up @@ -192,7 +193,7 @@ public extension Connectivity {
var isConnectedViaCellular: Bool {
return isConnected(with: ReachableViaWWAN)
}

var isConnectedViaEthernet: Bool {
return isConnectedUsingEthernet()
}
Expand All @@ -204,7 +205,7 @@ public extension Connectivity {
var isConnectedViaCellularWithoutInternet: Bool {
return isDisconnected(with: ReachableViaWWAN)
}

var isConnectedViaEthernetWithoutInternet: Bool {
return isDisconnectedUsingEthernet()
}
Expand Down Expand Up @@ -333,7 +334,7 @@ private extension Connectivity {
let dispatchGroup = DispatchGroup()
var tasks: [URLSessionDataTask] = []
var successfulChecks: UInt = 0, failedChecks: UInt = 0
let totalChecks: UInt = UInt(connectivityURLs.count)
let totalChecks = UInt(connectivityURLs.count)

// Ensure that we are using the latest session configuration.
urlSession = defaultURLSession()
Expand Down Expand Up @@ -483,7 +484,7 @@ private extension Connectivity {
return isConnected && reachability.currentReachabilityStatus() == networkStatus
}
}

func isConnectedUsingEthernet() -> Bool {
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 5.0, *), isNetworkFramework() {
guard let monitor = self.pathMonitor as? NWPathMonitor else {
Expand All @@ -510,7 +511,7 @@ private extension Connectivity {
return !isConnected && reachability.currentReachabilityStatus() == networkStatus
}
}

func isDisconnectedUsingEthernet() -> Bool {
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 5.0, *), isNetworkFramework() {
guard let monitor = self.pathMonitor as? NWPathMonitor else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

extension Notification.Name {
public static let ReachabilityDidChange = Notification.Name("kNetworkReachabilityChangedNotification")
public static let ConnectivityDidChange = Notification.Name("kNetworkConnectivityChangedNotification")
public extension Notification.Name {
static let ReachabilityDidChange = Notification.Name("kNetworkReachabilityChangedNotification")
static let ConnectivityDidChange = Notification.Name("kNetworkConnectivityChangedNotification")
}
16 changes: 8 additions & 8 deletions Connectivity/Classes/Model/ConnectivityStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import Foundation

@objc public enum ConnectivityStatus: Int, CustomStringConvertible {
case connected, // where a connection is present but the interface cannot be determined.
connectedViaCellular,
connectedViaCellularWithoutInternet,
connectedViaEthernet,
connectedViaEthernetWithoutInternet,
connectedViaWiFi,
connectedViaWiFiWithoutInternet,
determining,
notConnected
connectedViaCellular,
connectedViaCellularWithoutInternet,
connectedViaEthernet,
connectedViaEthernetWithoutInternet,
connectedViaWiFi,
connectedViaWiFiWithoutInternet,
determining,
notConnected

public var description: String {
switch self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
@objc
public enum ConnectivityResponseValidationMode: Int {
case containsExpectedResponseString,
equalsExpectedResponseString,
matchesRegularExpression,
custom
equalsExpectedResponseString,
matchesRegularExpression,
custom
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class ConnectivityResponseRegExValidator: ConnectivityResponseValidator {

public func isResponseValid(url _: URL, response _: URLResponse?, data: Data?) -> Bool {
guard let data = data, let responseString = String(data: data, encoding: .utf8),
let regEx = try? NSRegularExpression(pattern: regularExpression, options: options) else {
let regEx = try? NSRegularExpression(pattern: regularExpression, options: options)
else {
return false
}
let responseStrRange = NSRange(location: 0, length: responseString.count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Foundation
@objc
public enum ConnectivityResponseStringValidationMode: Int {
case containsExpectedResponseString,
equalsExpectedResponseString,
matchesRegularExpression
equalsExpectedResponseString,
matchesRegularExpression
}

@objcMembers
Expand Down
2 changes: 1 addition & 1 deletion Example/Connectivity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftformat >/dev/null; then\ncd ..\n swiftformat .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
shellScript = "if [ $ENABLE_PREVIEWS == \"NO\" ]\nthen\n SDKROOT=(xcrun --sdk macosx --show-sdk-path) \n swift run -c release --package-path ../tools/linting swiftformat \"$SRCROOT/Connectivity*\"\nelse\n echo \"Skipping the script because of preview mode\"\nfi\n";
};
3511C667F00570A014824B88 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Example/Connectivity/CombineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private extension CombineViewController {
strongSelf.updateNotifierButton(isCheckingConnectivity: strongSelf.isCheckingConnectivity)
}, receiveValue: { [weak self] connectivity in
self?.updateConnectionStatus(connectivity.status)
})
})
isCheckingConnectivity = true
updateNotifierButton(isCheckingConnectivity: isCheckingConnectivity)
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Connectivity/OriginalExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
class OriginalExampleViewController: UIViewController {
// MARK: Dependencies

fileprivate let connectivity: Connectivity = Connectivity()
fileprivate let connectivity = Connectivity()

// MARK: Outlets

Expand Down
2 changes: 1 addition & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tools/linting/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat.git",
"state": {
"branch": null,
"revision": "2dcce7fe2d6c245d8d669d394d5be5fe45d582fc",
"version": "0.49.8"
}
}
]
},
"version": 1
}
11 changes: 11 additions & 0 deletions tools/linting/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "linting",
platforms: [.macOS(.v10_11)],
dependencies: [
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.48.10"),
],
targets: [.target(name: "linting", path: "")]
)

0 comments on commit f7f70e7

Please sign in to comment.